How do I get the player from a surfacegui.Textbutton?

I want to make a button (inside the surfacegui) that defines player who clicked it.
This is the script so far.

script.Parent.MouseButton1Click:Connect(function()
    -- Yeah i don't know how to define it.
	game.ReplicatedStorage.RemotesPrompt.Robux1:FireClient(--Player)
end)
2 Likes

script.Parent.MouseButton1Click:Connect(function(player)
– Yeah i don’t know how to define it.
game.ReplicatedStorage.RemotesPrompt.Robux1:FireClient(player)
end)

I think that should work

Nope, It doesn’t work, but nice try tho

Try using a click ClickDetector

Uh, sorry but that doesn’t work. I don’t need to test it to know that…

script.Parent.MouseClick:Connect(function(plr)

print(plr.Name)

end)

Is there any way to change the design of the mouse on the click detector? (I don’t like it)

image

I’m confused, are you looking for the name of the player who clicks the button?

I mean its a textbutton INSIDE surfacegui.

No. Its a textbutton not in any startergui. Its inside a part

Try
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
print(player.Name)
end)

Just make a invisible part above the textbutton and use
script.Parent.MouseClick:Connect(function(player)

end)

No. It works on clicking, but I dont know how to define a player

What do you mean define a player? You can’t really create a new player
you can respawn them though

Please try this.

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
print(player.Name)
end)

What you can do is do

local player = game.Players.LocalPlayer

local plr = game.Players:GetPlayerFromCharacter(player.Character)

print(plr.Name)

(not 100% sure if it will work but try)

They are using a surface gui which can not hold localscript since they are located in workspace

This is your best bet I suggest you use it