Why do you need to destroy your buttons and put them back every 10 seconds?
Well, you can pass the player from local to server side with a RemoteEvent.
So on the client side you check for the MouseButton1Click and then fire the remote; on the server you just listen to OnClientEvent and do what you need there.
In this case you can listen to the ChildAdded event for the SurfaceGui and from there you just listen to the MouseButton1ClickEvent and as I wrote above, use a RemoteEvent.
Think of this like a pet system, but in a surface gui. Youâd need to delete all of the pet gui elements to periodically refresh the pet system gui.
Why would you need to delete the UI elements? You could just update them with the latest information.
thats just the easiest way implement it
No, it isnât. You canât expect help if youâre not going to put forth your best effort.
A text button will ALWAYS be client-side.
When itâs parented to the StarterGui folder inside of a ScreenGui instance, yes but in this instance itâs inside a SurfaceGui instance shared by the server.
You can just Parent the âSurfaceGuiâ to the StarterGui and set its âAdorneeâ property to a part. Use âLocalScriptâ also so you can define the player by âgame.Players.LocalPlayerâ
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Part = workspace.Part
local Gui = Part.SurfaceGui
local Button = Gui.TextButton
Button.MouseButton1Click:Connect(function()
print(Player.Name)
end)
repro.rbxm (5.8 KB)
No hacky solutions necessary, just have a local script (placed inside StarterPlayerScripts) handle the buttonâs behavior.
All of the TextButtonâs events that are inherited from GuiButton and GuiObject will only fire on the client. So as I said, itâll ALWAYS be client-side regardless of its parent.
https://developer.roblox.com/en-us/api-reference/class/TextButton
I was under the impression that you were inferring that the buttonâs existence itself was local.
A text button will ALWAYS be client-side.
All of the TextButtonâs events that are inherited from GuiButton and GuiObject will only fire on the client.
This is only correct if you listen for the event to fire on the client-side (via a local script), the RBXScriptSignal objects of GuiButton instances will fire on the server (if listened for via server script).
Thereâs no other way than to do it on the client side and communicate with the server via a remote event or function
You can put SurfaceGui to the StarterGui and change the SurfaceGui Adornee to the part. So now you can check if a player clicked on a textbutton and get the player who clicked it.