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

As far as I know, I don’t think there is a way to get a player just by clicking a “TextButton” when the script is server-side.

I think you will have to resort to using a localscript(that way you can get the LOCAL player),

Or just use a Clickdetector.

Clickdetector Doesnt work on GUI’S.

I Came up With a Way But it might be a Big Complicated.

I would make a Localscript that Says

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
      game.ReplicatedStorage.Robux1:FireServer(player)
end)

In a ServerScript do

game.ReplicatedStorage.Robux1.OnServerEvent:Connect(function(player)
        game.ReplicatedStorage.Robux1:FireClient(player)
end)

1 Like

Its a surface gui and only server script work on surfacegui’s
So you can’t use locaplayer

Ive had this problem before and I figured out how to fix it.
Put the SurfaceGUI into StarterGUI, set the adornee to the part you want to display on. Then you can code it exactly like a screenGUI

3 Likes

I know. So I Got the Players From a LocalScript And I got The Player, If you Fire the Server with the Player you can Get the Player From a ServerScript