Lua 检查实例*是否不';t*存在->&引用;“不是有效会员”;
第2行的“签入不是PlayerGui的有效成员”Lua 检查实例*是否不';t*存在->&引用;“不是有效会员”;,lua,roblox,Lua,Roblox,第2行的“签入不是PlayerGui的有效成员” function onClick(plr) if game.Players[plr.Name].PlayerGui.checkin ~= nil then print('player already has gui') else if game.ServerStorage.Players[plr.Name].Value == 0 then local gui = game.S
function onClick(plr)
if game.Players[plr.Name].PlayerGui.checkin ~= nil then
print('player already has gui')
else
if game.ServerStorage.Players[plr.Name].Value == 0 then
local gui = game.ServerStorage.GUIs.checkin:Clone()
gui.Parent = plr.PlayerGui
print('fresh gui being handed to '.. plr.Name)
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
如果实例上不存在成员,Roblox将立即抛出错误 如果不确定给定名称的子级是否存在,请使用
:FindFirstChild(name)
。它只返回nil
,而不是抛出错误
请注意,
MouseClick
已经给出了一个玩家,因此执行game.Players[plr.Name]
确实是多余的
if plr.PlayerGui:FindFirstChild("checkin") then
最好的做法是不在服务器上处理GUI。相反,您可以使用RemoteFunctions/RemoteEvents与本地脚本通信它们需要显示的内容。那么问题是什么?