首页 文章

Roblox错误:尝试索引本地'screengui'(零值)

提问于
浏览
0

Workspace.Part.Script:16:尝试索引本地'screengui'(零值)

wait(2) -- Testing to make sure assets loaded

script.Parent.Touched:connect(function(hit)
    if not hit or not hit.Parent then return end
    local human = hit.Parent:findFirstChild("Humanoid")
    if human and human:IsA("Humanoid") then
        local person = game.Players:GetPlayerFromCharacter(human.parent)
        if not person then return end
        person.Checklist.FirstEggCollected.Value = true
        local playgui = person:FindFirstChild('PlayerGui')
        print(playgui)
        wait(0.2)
        local screengui = playgui:FindFirstChild('ScreenGui')
        wait(0.2)
        print(screengui) -- This prints nil
        local collectnotice = screengui:FindFirstChild('CollectionNotice') -- This is line 16
        local Toggle = collectnotice.Toggle
        local text = Toggle.Text
        local value = text.Value
        value = "The Easy Egg!"
        person:WaitForChild('PlayerGui'):FindFirstChild('ScreenGui'):FindFirstChild('CollectionNotice').Toggle.Color.Value = Color3.fromRGB(0,255,0)
        person:WaitForChild('PlayerGui'):FindFirstChild('ScreenGui'):FindFirstChild('CollectionNotice').Toggle.Value = true
        script.Parent:Destroy()
        wait(5)
        game.Workspace.Variables.IfFirstEggInGame.Value = false
    end
end)

我已经在这几个小时了 . 不知道如何修复错误 . FE打开,是的,它的名字是“ScreenGui”,它在“PlayerGui”里面

错误:Workspace.Part.Script:16:尝试索引本地'screengui'(零值)

1 回答

  • 0

    来自Roblox手册:http://wiki.roblox.com/index.php?title=API:Class/Instance/FindFirstChild

    描述:返回使用给定名称找到的第一个子项,如果不存在此类子项,则返回nil .

    所以似乎没有名为“ScreenGui”的孩子 .

    如果函数可能返回nil,则必须正确处理 . 盲目地索引可能的零值是不好的做法 .

相关问题