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

Error: Attempt to index a nil value?

Asked by 6 years ago

title is my error, what is wrong? it says its something in line 3...

game:GetService("Players").PlayerAdded:Connect(function(player)
    local Como = player.PlayerGui:FindFirstChild("Password")
    Como.Enabled = true
    game.Lighting.Blur.Enabled = true
    local Hobo = player.Character:FindFirstChild("Humanoid")
    Hobo.WalkSpeed = 0
end)

1 answer

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

Instance:FindFirstChild() returns the instance with the provided name if it exists, or otherwise returns nil. In your case, your call is redundant because you do not check if it returned nil.

GUIs cloned client-side won't replicate to the server (i.e. cloned from game.StarterGui), so the server was unable to find your GUI.

Player.Character is not loaded when game.Players.PlayerAdded fires, try the Player.CharacterAdded event like so:

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        -- code
    end)
end)
0
Thanks i already fixed it! SuperBeeperman 30 — 6y
0
jesus christ I could've sworn you were at 78 points 1 month ago what Fifkee 2017 — 6y
Ad

Answer this question