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

Player is a Nil Value?

Asked by 8 years ago

This is a regular script, inside a TextButton, inside a frame, inside another frame, inside a SurfaceGui.

    if player.Name == bin.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Owner.Value then
        if toggle == true then
            toggle = false
            bin.Style = Enum.ButtonStyle.RobloxRoundButton
            bin.TextColor3 =, 0/255, 0/255)
            bin.Text = "Allow Visitors: Off"
            toggle = true
            bin.Style = Enum.ButtonStyle.RobloxRoundDefaultButton
            bin.TextColor3 =, 255/255, 255/255)
            bin.Text = "Allow Visitors: On"

The output says: Workspace.Kiosk.Screen.Screen.Screen.Frame.Frame.Button.Scr:5: attempt to index local 'player' (a nil value)

Not sure why it says player is a nil value with the player parameter. Any help?

2 answers

Log in to vote
Answered by
iaz3 190
8 years ago

As the wiki says

Note: SurfaceGuis must be descendants of PlayerGui in order to know the player who is interacting with it.

But don't worry, this is not as complicated as it sounds, you simply move the surface GUI to starter GUI, and set the Adornee property of the surface GUI, and make your script local.

Adornee: Sets the object that the SurfaceGui is adorned too. In other words, this defines which Part the SurfaceGui is attached to.

You will then be able to find the player using game.Players.LocalPlayer

Also, MouseButton1Click does not return the player who clicked

Thank you! I've never made an adorned object so it was a bit new to me. Thanks! sidekick83 80 — 8y
You're welcome! iaz3 190 — 8y
Log in to vote
Answered by 8 years ago

"Player" is not what you think it will be. Just putting "player" is just a variable representing something. To know what that something is, do print(player). You should be using a Local Script so you can go to the character easily by doing game.Players.LocalPlayer. You're working with a GUI so it's actually the best idea to use a Local Script. This will also cut down on all those nasty "Parents" you have.

Thanks! sidekick83 80 — 8y

Answer this question