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

Player is being output as a nil value? [Solved]

when ever i try to get the player from clicking a button it's not giving the player.

script.Parent.MouseButton1Click:Connect(function(Player)
	print(Player.Name)
end)

This is whats goes in the Output

21:59:51.442 - Players.Dusk_Toxic.PlayerGui.LevelBar.TextButton.LocalScript:2: attempt to index local 'Player' (a nil value)
21:59:51.443 - Stack Begin
21:59:51.444 - Script 'Players.Dusk_Toxic.PlayerGui.LevelBar.TextButton.LocalScript', Line 2
21:59:51.444 - Stack End

4 comments

0

the player isn't passed through the MouseButton1Click signal

0

You're probably doing this on a local script so just index the local player in the player's service

0

The thing is i want to be able to get it to send a Remote Function through the button but it's not even detecting the player

0

I got it fixed Thanks Sinister

1 answer

✓ Accepted answer

the MouseButton1Click:Connect(function(arg) return argument nil, and not is the player.

You need to get player with game.Players.LocalPlayer

example:


local Player = game.Players.LocalPlayer -- This only works in Local Script / Get local player.

script.Parent.MouseButton1Click:Connect(function()
	print(Player.Name)
end)

Hope it helped :)

Wiki pages:

LocalPlayer


Solved your problems? put in title [SOLVED] or accept a answer.

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