How to get the player how clicked in a TextButton

I want a local script that gets the player when the player click in a TextButton (Inside a ScreenGui)

I can’t make it .-.

I already tried use the LocalPlayer option but this will crash other script.

3 Likes

Why does game.Players.LocalPlayer crash? Did you forget to write Players before LocalPlayer?

Also show the script pls ;-;

1 Like

I don’t think that could crash a device?

1 Like

Place a local script under the button and type:

script.Parent.MouseButton1Click:Connect(function(click)
	local player = game.Players.LocalPlayer
	print(player.Name.." pressed the button.")
end)

I tried it and it doesn’t crash the device at all and it works perfectly.

4 Likes

@vRaphy @D0RYU

It doesn’t crash this local script, but crash the other script of the serverscriptservice, because it’s firing a remote event.

Because the other script thinks that the LocalPlayer is all players.

The only thing I can think of is using a MouseButton1Click Parameter

TextButton.MouseButton1Click:Connect(Function(Player)
Print(Player)
End)

Maybe something in the lines of that meets your intention?

1 Like

It print “nil” and if i put Player.Name, appear an error saying that the parameter doesn’t have a name

1 Like

Oh, I tought it would work since I have seen other problems similar to this, but never tried it, I hope you will find a solution for this

1 Like

This is incorrect syntax and there’s no Player parameter for the GuiButton.Mousebutton1Click event.

1 Like

When calling RemoteEvent:FireServer() in a LocalScript, the receiving end which will be the RemoteEvent.OnServerEvent event in a Script will always have its first parameter reserved for the Player instance which refers to the player who fired the event.

Read this for a thorough tutorial regarding the topic: Bindable Events and Functions | Roblox Creator Documentation

2 Likes