Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you access a Gui from ServerScriptService script?

Asked by
sheepposu 561 Moderation Voter
5 years ago

Anytime I try to access a Gui form PlayerGui I get an error in not being able to find it. Can someone help me? Thx in Advance. BTW - I use WaitForChild

0
Server Scripts cannot access (read or change) the PlayerGui without having placed the Gui there themselves SerpentineKing 3885 — 5y

1 answer

Log in to vote
1
Answered by
Mr_Unlucky 1085 Moderation Voter
5 years ago
Edited 5 years ago

This is because normal scripts can't get local scripts. If you really want normal scripts to access GUIs you should use RemoteEvents.

SERVER SCRIPT

local remoteEvent = game.ReplicatedStorage.RemoteEvent --The remoteEvent

remoteEvent:FireAllClients() --Fire the remoteEvent for all clients/players.

LOCAL SCRIPT

local remoteEvent = game.ReplicatedStorage.RemoteEvent --The remoteEvent
local label = script.Parent --The TextLabel

remoteEvent.OnClientEvent:Connect(function() --When the remoteEvent fires for clients. E.g FireAllClients
    label.Text = "Hello World!" --Change the text to "Hello World!"
end)

The scripts above is a hypothetical situation in which you want to change a GUI's TextLabel's text into "Hello World!" using a server script. We use a remote event and fire it for clients/players so that they could see it.

0
I usually use this stuff for things like map voting GUIs and other stuff. You can use it for that direct purpose as well. Mr_Unlucky 1085 — 5y
Ad

Answer this question