How would i activate a button of a screen gui that's in the workspace, not playergui?

Greetings,

I’m making money printers, that a player places on the ground and the accumulate currency then by clicking on a button they are suppose to be able to withdraw the amount.

First I put the gui inside StarterGui, but then i realized that when the player respawns he can’t see the gui. So now I’ve decided to put the gui inside the printer itself, however, because it’s now on the server i can’t activate the button which was activated via a local script before.

I can only activate it with a Script and MouseButton1Click but this prevents me from knowing who clicked the button.

So now I am trying to figure out how i would activate the button and detect who clicked it, to check if the player who clicked it is the owner of the printer.

Please advise, thank you for your time

I am 100% sure that the reason it isn’t functioning in a LocalScript for you is because it’s not in either StarterPlayerScripts or PlayerGui
image

(Code that I tested this with)

workspace.Part.SurfaceGui.TextButton.MouseButton1Click:Connect(function()
	print("ran")
end)

The way I would go about this is do the MouseButton1Click via client then use a RemoteEvent and let the server withdraw money for the player, good luck :smiley:

I know that, the thing is how would i reference what button i mean when the printer is in replicated storage and i clone it into the game every time a printer is placed down

If you’re still willing to put the GUI into StarterGui, have you tried turning the ResetOnSpawn property of your ScreenGui to false?


By default it is turned on, which makes the GUI reset to its original state whenever the player respawns.

If you are intent on doing it server-sided, have you considered setting a part with a ClickDetector over the button? The MouseClick event will pass along the player who clicked the part.

I’d use .ChildAdded from the localscript, or you can use CollectionService from the server (since they replicate)

Thank you so much, that simple solution is just what i needed