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

How would i clone a GUI from serverstorage to playergui?

Asked by
Kblow1 53
6 years ago

How do i clone a GUI from serverstorage to playerGui on the touch of a brick? Thanks!

script.Parent.Touched:connect(function(p)
local humanoid = p.Parent:findFirstChild("Humanoid")
if (humanoid ~= nil) then
humanoid.Torso.CFrame = CFrame.new(-116.49,0.9,-7.73)
-------------------
local plr = p.Parent:findFirstChild("Player")
script.Parent.Parent.Parent.ServerStorage.LeaveButton.Exit.Clone().Parent = plr
end
end)
0
PlayerGui not just player greatneil80 2647 — 6y

2 answers

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

You could try this server-sided script. This script will not work if it is a LocalScript or if FE is enabled:

script.Parent.Touched:Connect(function(hit)
        local p = game.Players:GetPlayerFromCharacter(hit.Parent)
        if p then
                p.Character.Torso.CFrame = CFrame.new(-116.49, 0.9, -7.73)
                game.ServerStorage.LeaveButton.Exit:Clone().Parent = p.PlayerGui
        end
end)
0
No User#19524 175 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

You wouldn't put a GUI in ServerStorage. Put it in Replicatedstorage. The ServerStorage is for the server only, while the replicatedstorage is client and server. We need it. Plus the server does not handle GUI AT ALL.

-- Local Script, Put the remote event in Replicatedstorage so server and client can access it

local rep = game:GetService("ReplicatedStorage")
local gui = rep.Gui
local plr = game:GetService("Players").LocalPlayer

rep.ShowGui.OnClientEvent:Connect(function()
    if not plr.PlayerGui:FindFirstChild("Gui") then -- Make sure player can't get flooded
        gui:Clone().Parent = plr.PlayerGui
    end
end)

Server Script inside part which fires this remote event:

-- The Client Event function fires FireClient.

script.Parent.Touched:Connect(function(part)
    local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
    if plr then
        game:GetService("ReplicatedStorage").ShowGui:FireClient(plr) -- specified plr as 1st arg
    end
end)

Answer this question