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

Cloning a GUI from ReplicatedStorage to a player?

Asked by 4 years ago
  • 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

Log in to vote
2
Answered by
Lakodex 711 Moderation Voter
4 years ago
Edited 4 years ago

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

Ad
Log in to vote
2
Answered by 4 years ago
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)
1
@MaximussDev Thanks Dude! I forgot all about WaitForChild. Lakodex 711 — 4y
1
No problem. Just saw that and I know that I make this mistake very frequently. Thanks for the original script! MaximussDev 86 — 4y

Answer this question