Localplayer name not working?


I got an issue. So I am trying to make a staff board (where people click a button and their name will appear on the board in-game).

For some reason ‘play.Name’ does not work and gives me an error.

local playerservice = game:GetService("Players")
local player = playerservice.LocalPlayer

function Click(mouse)
	workspace.Board.SurfaceGui.ImageLabel.Host.Text = player


Error: 13:47:29.760 Players.BrewBakeries.PlayerGui.ScreenGui.TextButton.Script:5: attempt to index nil with 'Name' - Server - Script:5

I hope someone can help me, thank you already!

Regular scripts cannot access LocalPlayer, you need a localscript for that

Edit: If you want it to update something to everyone on the server when pressed, you need to use a RemoteEvent

Ohh, alright. Thank you.

I haven’t worked before with RemoteEvent, how would that work?

It’s quite simple!

First add a RemoteEvent into ReplicatedStorage, then add a Script in ServerScriptService, to make it so when the Event is fired, it’ll change the text to the player who fired the event

Something like this

local repStore = game:GetService("ReplicatedStorage")

	workspace.Board.SurfaceGui.ImageLabel.Host.Text = player.Name

And then in your localscript, just change it to this

function Click()


Do not pass in the player instance yourself, it already knows who the palyer who fired the event is, you only have to pass in additional parameters

Oml, thank you very much.

yk limit

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

Also I think I would recommend if you make a cooldown for the button pressing, because someone with an autoclicker could fire the event so many times it can cause issues, so make sure to limit the amount of pressing using a cooldown!

Alright, last thingy :joy:

Let’s say I wanna have different roles on the board, creating 10 different RemoteEvents is not really handy, how could I do that?

So there will be 10 different buttons on your GUI and 10 different ‘categories’ on the board. How can I do that or do I need to create 10 different RemoteEvent?

As I mentioned before, you can give parameters to the RemoteEvent, as an example to show you want I mean. Let’s go back to the code we used and do some changes

local repStore = game:GetService("ReplicatedStorage")

repStore.RemoteEvent.OnServerEvent:Connect(function(player, text)
	workspace.Board.SurfaceGui.ImageLabel.Host.Text = player.Name

And now we just fire in a text to print

function Click()
	game:GetService("ReplicatedStorage").RemoteEvent:FireServer("This is a test")


And now whe nyou press the button, it’ll change the text and print This is a Test

That’s the basis of how you can set it up to make it use only a singular event rather than multiple via adding parameters. Just make sure to not trust the client and do checks on the arguments they fired since exploiters

Awh, thanks for helping me. This worked :joy:

1 Like