Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Player is a Nil Value?

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

✓ Accepted answer

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

2 comments

1

Thank you! I've never made an adorned object so it was a bit new to me. Thanks!

0

You're welcome!

"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.

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.