I'm trying to make a simple script right now that returns the name of the player who clicked a SurfaceGui button and I know I'm doing something wrong. Here's the code I have for it.
button = script.Parent
button.MouseButton1Click:connect(function(plr)
button.Parent.CurrentHostText.Text = "Current Host: " ..plr.Name
end)
My output says "Attempt to index local 'plr' (a nil value)". Does MouseButton1Click not return the player who clicked it? If so, is there another way to accomplish this then?
EDIT
I forgot to mention that Filtering Enabled is enabled.

3 comments
I appreciate your answer as it sounds like it would work. But the SurfaceGui is located inside the Workspace because I need everyone to be able to see which player clicked the button. With Filtering Enabled active, it wouldn't show the change to anyone else but the client?
Oh, then just have a localscript where when the player clicks on the button, it fires up a remoteevent to the server telling the server that a player clicked on the button. Then you can handle it from there.
I think I see where you're coming at. Thanks for the help!