Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 检查实例*是否不';t*存在->&引用;“不是有效会员”;_Lua_Roblox - Fatal编程技术网

Lua 检查实例*是否不';t*存在->&引用;“不是有效会员”;

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

第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.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与本地脚本通信它们需要显示的内容。

那么问题是什么?