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

how to enable gui using a normal script in serverscriptservice?

Asked by
mewtify 26
2 years ago

I have an on on touch function in a script located in serverscriptservice and I would like to enable a gui in it. I can't figure out how to do this since I only have experience showing guis with local scripts.

Here was my original code which did not work

            local gui = hit.Parent.PlayerGui:FindFirstChild("Gui")
            if gui then
                gui.Enabled = true
            end

How would I navigate to the playergui through the ontouch? I have also thought of cloning the gui into the playergui, but I am not sure how I would do that and if that would even work.

Any help or advice is appreciated, thank you

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

Hit.Parent is the character of the player, not the player instance.

try this instead:

local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local gui = plr.PlayerGui.Gui

if gui and plr then
    gui.Enabled = true
end

Note: this script was not tested

0
Using the :Clone() method may be a viable option, or you can fire a RemoteEvent to the Client. NotThatFamouss 605 — 2y
0
It worked great, thank you! mewtify 26 — 2y
Ad

Answer this question