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)
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)
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)