-
I want a button on a surface gui. The problem I need to get the player. What is the best way to get a player when they click on a button on a surface gui. (A script not a local script)
-
I asked some people and gave no response.
You should treat a surface GUI like any other client-sided UI; Use a localscript to listen for a click.
Mhm. I am trying to make a system more on the server side not really client side. Remeber it is a surface gui on a part.
‘’’
script.Parent.MouseButton1Down:Connect(function(plr)
Player = plr
End)
‘’’
Sorry this was wrote on mobile
There is a plr parameter in mousebuttondown. Let me check.
I would guess so, never created a server side gui.
Anything GUI related should really be dealt with client-side, as it is redundant using the server to do such tasks. If you really need the server to interact for this scenario, you can just use a remote event/ function to do so. Plus, it sends the player object as you initially wanted!
local GUI = workspace.ur.gui
local button = GUI:WaitForChild("your_Button")
local Player = game:GetService("Players").LocalPlayer
local Remote = ur.Remote
button.MouseButton1Click:Connect(function()
Remote:FireServer()
end)
-- Server
local remote = ur.remote
remote.OnServerEvent:Connect(function(Player)
print("Voila! I got the player object! The player's name is " .. Player.Name)
end)
Remeber tho. This is a textbutton on a surface gui.
I know one method but just want to know if there is a better method.
Your trying to get the Player from the Server-side, correct? If so then,
game.Players.PlayerAdded:Connect(function(player)
--[[ do stuff here]]
end)
No like there is a button on a surface gui. The person clicks on the button. What is the best way to get the player that clicked on the button?
As what everybody else has been saying, the best option is for it to be Client-Sided.
( Local Script )
It doesn’t matter that it’s on a surface GUI, you should still use remotes and a local script. What other method are you using?
So put a local script in starter gui and if the player clicks on the button it just fire a remove event?
That was the method I was gonna use but just wanted to know if there is a better way.
I assure you this is the best way. I believe there is no way to detect the player who clicked the button on the server anyways.
Just use the method that AbiZinho just shown you:
You can put a local script in the Surface GUI and use the same code and fire the server using AbiZinho’s method. Treat it like it was in the player’s StarterGui.
Yea I will need to make it client sided. Thx to everyone who helped me.
Put the SurfaceGui in StarterGui, then set its adornee to the part you want it to be on. From there you can listen for inputs from a localscript.