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

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.

bin.MouseButton1Click:connect(function(player)
    if player.Name == bin.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Owner.Value then
        bin.Parent.Parent.Parent.Click:Play()
        if toggle == true then
            toggle = false
            bin.Style = Enum.ButtonStyle.RobloxRoundButton
            bin.TextColor3 = Color3.new(0/255, 0/255, 0/255)
            bin.Text = "Allow Visitors: Off"
        else
            toggle = true
            bin.Style = Enum.ButtonStyle.RobloxRoundDefaultButton
            bin.TextColor3 = Color3.new(255/255, 255/255, 255/255)
            bin.Text = "Allow Visitors: On"
        end
    end
end)

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
1
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

1
Thank you! I've never made an adorned object so it was a bit new to me. Thanks! sidekick83 80 — 8y
0
You're welcome! iaz3 190 — 8y
Ad
Log in to vote
1
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.

0
Thanks! sidekick83 80 — 8y

Answer this question