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

Cloning a GUI from ReplicatedStorage to a player?

  • StarterCharacterScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Clone = ReplicatedStorage.SprintC
local player = game.Players.LocalPlayer

player.PlayerAdded:Connect(function()
	Clone:FireServer("Sprint")
end)
  • ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Clone = ReplicatedStorage.SprintC
local GUI = ReplicatedStorage.Sprint:Clone()
local player = game.Players.LocalPlayer

Clone.OnServerEvent:Connect(function()
	GUI.Parent = player.PlayerGui
end)
  • ReplicatedStorage RemoteEvent "SprintC" GUI "Sprint"

I am only using serverscripts not local scripts.

When a player joins it fires a SprintC remote and that will clone sprint from the replicatedstorage but why is it not working? Please help! Thanks in advance!

2 answers

You cannot have This in a sever script.

local player = game.Players.LocalPlayer

Here's your fixed script. You only need one in StarterGUI as a localscript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GUI = ReplicatedStorage.Sprint
local player = game.Players.LocalPlayer

player.PlayerAdded:Connect(function()
    	GUI:Clone().Parent = player.PlayerGui
end)

If this works close this as working! if not reply, This is the only way without the script breaking on you. It works the same on what you are attempting to do, If you are just using serverscripts You're game may not get as many upvotes because of the bugs of the game

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GUI = ReplicatedStorage.Sprint
local player = game.Players.LocalPlayer

player.PlayerAdded:Connect(function()
        GUI:Clone().Parent = player.PlayerGui
end)
  • @HeyItzscoop

So I'd just like to add to this.

Since this might return an error, you want to yield when looking for the PlayerGui, since it needs to load into the player.

-- THIS IS JUST A CHANGE OF HeyItzscoop's SCRIPT.  ALL CREDIT TO HIM.--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GUI = ReplicatedStorage.Sprint
local player = game.Players.LocalPlayer

player.PlayerAdded:Connect(function()
        GUI:Clone().Parent = player:WaitForChild("PlayerGui") -- Wait for up to 5 seconds to look for the PlayerGui "constantly" (Not really, just every ____ amount of time).
end)

2 comments

1

@MaximussDev Thanks Dude! I forgot all about WaitForChild.

1

No problem. Just saw that and I know that I make this mistake very frequently. Thanks for the original script!

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