Lua 我不断地遇到这个错误,我不知道';我不知道是什么
好的,我制作了一个roblox脚本,它提供了一个随机武器,它是用Lua编写的 我不断地犯这个错误Lua 我不断地遇到这个错误,我不知道';我不知道是什么,lua,roblox,Lua,Roblox,好的,我制作了一个roblox脚本,它提供了一个随机武器,它是用Lua编写的 我不断地犯这个错误 script.Parent.MouseButton1Click:connect(function(player) local BackPack = player.BackPack wait(0.5) if player.Leaderstats.Money >= 100 then local randomizer = math.random(0,10)
script.Parent.MouseButton1Click:connect(function(player)
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)
好的,我制作了一个roblox脚本,它提供了一个随机武器,它是用Lua编写的
我不断地犯这个错误
script.Parent.MouseButton1Click:connect(function(player)
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)
12:40:50.574-Players.Player1.PlayerGui.Shop.Main.Frame.RCK.randomweapons2:2:尝试索引全局“玩家”(零值)
12:40:50.575-堆栈开始
12:40:50.576-脚本
“玩家。玩家1。玩家界面。商店。主机。画面。RCK。随机武器2”,第2行
12:40:50.576-堆栈结束
.MouseButton1Click
事件不会将player
作为参数传递,请将player
定义为game.Players.LocalPlayer
,这样您就可以避免所面临的问题,因为定义的player
是一个空值,因为没有随事件传递参数。如果您的推理是因为它是一个surface/billboard 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)
希望这有帮助 错误不在提供的代码中…从内部函数的参数列表中删除
player
MouseButton1Click:connect()function@EgorSkriptunoff现在我很困惑。如果是函数的参数,玩家怎么可能是全局的?@Pieget-是的,错误消息是否正确还不清楚。但我非常确定鼠标点击roblox事件不太可能将一些非鼠标数据(一个player
值)传递给鼠标事件处理程序