Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would i clone a GUI from serverstorage to playergui?

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)

1 comment

0

PlayerGui not just player

2 answers

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)

1 comment

0

No

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.