Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My output says "Attempted to index nil with 'WaitForChild'", what went wrong?

Asked by 4 years ago
Edited 4 years ago

I'm trying to make some code to open a GUI when I press a certain key. It's going well but something went wrong. My code:

local UserInputService = game:GetService("UserInputService")
while game.Players.LocalPlayer ~= nil do
    wait(0.08)
end
local Player = game:GetService("Players").LocalPlayer
wait(1)
local PlayerGui = Player:WaitForChild("PlayerGui")

function enable()
    script.Parent.Enable.Value = 1
    while game.Lighting.Blur.Size < 10 do
        game.Lighting.Blur.Size = game.Lighting.Blur.Size + 2
        wait(0.1)
    end
end
function disable()
    script.Parent.Enabled = 0
    while game.Lighting.Blur.Size > 0 do
        game.Lighting.Blur.Size = game.Lighting.Blur.Size - 2
        wait(0.1)
    end
end

UserInputService.InputBegan:Connect(function(Input, GameProcessed)
    if (Input.KeyCode == Enum.KeyCode.P) then
        for _,v in pairs(PlayerGui:GetChildren()) do
            if (v:IsA("ScreenGui")) then 
                if script.Parent.Enable.Value == 0 then
                    enable()
                    v.Enabled = true
                end
                if script.Parent.Enable.Value == 1 then
                    disable()
                    v.Enabled = false
                end
            else
                if script.Parent.Enable.Value == 0 then
                    enable()
                    v.Visible = true
                end
                if script.Parent.Enable.Value == 1 then
                    disable()
                    v.Visible = false
                end
            end
        end
    end
end)
0
On line 2-4, it looks like the script is waiting for LocalPlayer to be nil. After that, LocalPlayer is nil. So when refrencing LocalPlayer, it's nil. Diamo_YT 68 — 4y
0
I just noticed that... AHHHHHHHHHHHHHHHHHHHHHHHHH ??????? brianxu 0 — 4y

Answer this question