Can Server Scripts Access PlayerGui?

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
	local UI = plr.PlayerGui:WaitForChild("UI")
	UI.Button.MouseButton1Down:Connect(function()
		print("yepee!")
	end)
end)

For years I thought the script above was impossible to do, given that the script is a Server Script running on ServerScriptService.
Curiosity killed the cat and while I was working on something I decided to test it for fun, assuming it will not work. To my surprise it did!

This is confusing me, as I always thought the only way to detect UI changes was with a LocalScript and a Remote Event. However, the above script works without any of that.
Is it safe to use the above script? Or is it just something else that is commonly labeled as “Unsafe” and ect? Can I trust the UI that the server is referencing?

I am more so confused on the how it works. Because based on my knowledge, it shouldn’t.

the server can see PlayerGui because it’s replicated but it can’t actually receive UI input reliably. what you saw “working” is just the client firing the event locally.

so always handle UI in LocalScripts âžť send to server with RemoteEvents.

what you’re seeing is just a side-effect of replication, not true server-side input handling i believe.

2 Likes

This appears to be fine to do but at the cost of server latency and client latency it also isnt the most efficient because you can just create a remote event that can also send the same information to the server but completely customizable and you can include data in the remote event

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.