Get a username of someone that clicked a button in a normal script

How would I go about doing this as I can’t do what I want to do inside of a localscript but then again I don’t know how to get the username in an actual script, can anybody help? Thanks!


script.Parent.MouseButton1Clicked:Connect(function(player)

print(player.Name)

end)

Put a click detector inside a part/model and put a script inside it. Paste the following code:

script.Parent.MouseClick:Connect(function(plr)
local playername = player.Name --username of player
end)
1 Like

You do realise that this isn’t a localscript so (player) will just be nil

No, it will not be nil. Try it out for yourself.

If you put player inside the function brackets it won’t go nil

I don’t want it to be on a click detector though I mean on a gui

No it won’t. The click detector is getting the argument of the event and not referring to LocalPlayer as a local script can do

You need a local script to manipulate GUI’s?

Next time mention it in the first post for more information. Anyways here’s the modified code:

script.Parent.MouseButton1Click:Connect(function(player)
   local username = player.Name
end)

He/she probably has the GUI in a workspace part.

1 Like

Two things: MouseButton1Clicked is not an event, MouseButton1Click.

Also, a GuiObject does not provide the player parameter in the signal.

Maybe use a ClickDetector instead, or use a ProximityPrompt.

Edit: @NeoGaming_RBLX that is not going to work, look at my answer above :man_facepalming:

5 Likes