好的,我制作了一个roblox脚本,它提供了一个随机武器,它是用Lua编写的 我一直收到这个错误
globalVariable
好的,我制作了一个roblox脚本,它提供了一个随机武器,它是用Lua编写的 我一直收到这个错误
12:40:50.574 - Players.Player1.PlayerGui.Shop.Main.Frame.RCK.randomweapons2:2:尝试索引全局'玩家'(零值) 12:40:50.575 - Stack Begin 12:40:50.576 - 剧本 'Players.Player1.PlayerGui.Shop.Main.Frame.RCK.randomweapons2',第2行 12:40:50.576 - Stack End
答案 0 :(得分:1)
.MouseButton1Click
事件未将player
作为参数传递,之前将player
定义为game.Players.LocalPlayer
,您将避免遇到的问题因为定义的player
是一个零值,因为没有参数与事件一起传递。如果你背后的推理是因为它是一个表面/广告牌GUI,那么只需将GUI设置为玩家的PlayerGui
(将其放在StarterGui
中)并将GUI的装饰设置为之前所在的部分。 。这是固定代码:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
local BackPack = player.BackPack
wait(0.5)
if player.Leaderstats.Money >= 100 then
local randomizer = math.random(0,10)
if randomizer == 1 then
local knife1 = game.Lighting.CookieKnife:Clone()
knife1.Parent = BackPack
elseif randomizer == 2 then
local knife2 = game.Lighting.Cleaver:Clone()
knife2.Parent = BackPack
elseif randomizer == 3 then
local knife3 = game.Lighting.RustyCleaver:Clone()
knife3.Parent = BackPack
elseif randomizer == 4 then
local knife4 = game.Lighting.WhiteCleaver:Clone()
knife4.Parent = BackPack
elseif randomizer == 5 then
local knife5 = game.Lighting["Sparkley Knife"]:Clone()
knife5.Parent = BackPack
elseif randomizer == 6 then
local knife6 = game.Lighting.CommonKnife:Clone()
knife6.Parent = BackPack
elseif randomizer == 7 then
local knife7 = game.Lighting.CommonKnife:Clone()
knife7.Parent = BackPack
elseif randomizer == 8 then
local knife8 = game.Lighting.CookieKnife:Clone()
knife8.Parent = BackPack
elseif randomizer == 9 then
local knife9 = game.Lighting.ExpensiveKnife:Clone()
knife9.Parent = BackPack
elseif randomizer == 10 then
local knife10 = game.Lighting.CookieKnife:Clone()
knife10.Parent = BackPack
end
end
end)
希望这有帮助!