我正在编写一个脚本来检测一个人使用他们的名字,但我似乎无法让它工作。还请指出我在脚本中所做的任何错误都会有所帮助。
game.Workspace:WaitForChild("Console")
print("Waited")
game.Players.PlayerAdded:Connect(function(plr)
print("Connected")
if game.Workspace.Console and plr.Name == "wojciechpa2007" then
local Console = game.Lighting.Console:Clone()
Console.Parent = plr.Startergui
print("Cloned")
elseif
not game.Workspace.Console and plr.Name == "wojciechpa2007" then
plr.Startergui.Console:Destroy()
print("Destroyed")
end
end)
heyo,
此脚本中包含竞争条件。第一行game.Workspace:WaitForChild("Console")
将阻止执行脚本的其余部分,直到加载对象或达到超时。
这意味着玩家可以在脚本可以收听game.Players.PlayerAdded
信号之前加入游戏。
StarterGui也不存在于特定的玩家身上。它存在于游戏级别,并且当玩家的角色加载到游戏中时,它会将其内容转储到玩家的PlayerGui中。
所以要修复你的脚本,你可以尝试这样的事情:
-- right away connect to the PlayerAdded signal
game.Players.PlayerAdded:Connect(function(plr)
print("Player Joined!", plr.Name, plr.UserId)
-- do something special if wojciechpa2007 joins
if plr.Name == "wojciechpa2007" then
print("wojciechpa2007 joined! Adding console!")
-- add the special console into the player's PlayerGui for when they load
local Console = game.Lighting.Console:Clone()
Console.Parent = plr.PlayerGui
end
end)
这里有一些建议和注意事项:
希望这可以帮助!