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

Why doesn't this script clone the GUI to PlayerGui?

Why doesn't this script clone the Gui to PlayerGui? How can this be fixed?

Code:

game.Players.PlayerAdded:Connect(function(plr)
	
    local LSystem = plr:WaitForChild("LevelSystem")
    local PStats = plr:WaitForChild("PlayerStats")
    local level = LSystem:WaitForChild("Level")
    local points = PStats:WaitForChild("Points")

    level.Changed:Connect(function(val)
        points.Value = 0
        repeat wait () until plr.Character
	local LevelUpCongrats = script.LevelUpCongrats:clone()
	LevelUpCongrats.Parent = plr.PlayerGui 
    end)
end)

5 comments

0

switch to :Clone(). clone() was deprecated

0

That didn't fix it :(

0

hmm this question is really good, I will try to make it stick out so more people can help, meanwhile, I will place this function in a brick or a system and I will find out

0

Thank you

4 answers

✓ Accepted answer

Well, this doesn't answer your question directly, but this is a solution. Also, just a tip, handle GUI on the client

IN A LOCAL SCRIPT IN PLAYER

plr = game.Players.LocalPlayer
    local LSystem = plr:WaitForChild("LevelSystem")
    local PStats = plr:WaitForChild("PlayerStats")
    local level = LSystem:WaitForChild("Level")
    local points = PStats:WaitForChild("Points")

    level.Changed:Connect(function(val)
        points.Value = 0
        repeat wait () until plr.Character
    local LevelUpCongrats = script.LevelUpCongrats:Clone()
    LevelUpCongrats.Parent = plr.PlayerGui 
-- Extra Bit
wait(5)
LevelUpCongrats:Destroy()
    end)
end)

Also I added a part to destroy the notification after 5 sec. Remove if you want

1 comment

0

Put this in Game>StarterScripts>StarterPlayerScripts

game.Players.PlayerAdded:Connect(function(plr)

    local LSystem = plr:WaitForChild("LevelSystem")
    local PStats = plr:WaitForChild("PlayerStats")
    local level = LSystem:WaitForChild("Level")
    local points = PStats:WaitForChild("Points")

    level.Changed:Connect(function(val)
        points.Value = 0
        repeat wait () until plr.Character
    local LevelUpCongrats = script.LevelUpCongrats:Clone()
    LevelUpCongrats.Parent = plr:WaitForChild("PlayerGui") 
    end)
end)

1 comment

0

I tried this but it still isn't working. Maybe I'm doing something wrong? I placed the script inside ServerScriptService then I placed the GUI in the script. I tried LocalScript and a normal script.

So what I would do is actually use WaitForChild in order to make this script work. Also just to be cautious, I would put the GUI in ServerStorage.

local SS = game:GetService("ServerStorage")
local LevelUp = SS:WaitForChild("LevelUpCongrats")

game.Players.PlayerAdded:Connect(function(plr)
	
local plrgui = plr:WaitForChild("PlayerGui")
    local LSystem = plr:WaitForChild("LevelSystem")
    local PStats = plr:WaitForChild("PlayerStats")
    local level = LSystem:WaitForChild("Level")
    local points = PStats:WaitForChild("Points")


    level.Changed:Connect(function(val)
        points.Value = 0
        repeat wait () until plr.Character
    local levelgui = LevelUp:Clone()
	levelgui.Parent = plrgui
    end)
end)

Hopefully this helped! (If this didn't I would try converting this into a LocalScript, since this only requires the Player's GUI, not everyone's GUI.)

-LukeGabrieI

2 comments

0

I'm not sure what I'm doing wrong but it still isn't working?

0

Did you put the GUI in ServerStorage and the Script in ServerScriptService?

Hey, Professional_Lua beat me to it, but on line 12 change the

LevelUpCongrats.Parent = plr.PlayerGui

to

LevelUpCongrats.Parent = plr:WaitForChild("PlayerGui")

By adding WaitForChild, it allows the system to compute .Hopefully this works, if it does, accept this answer, or Professional_Lua's, but I have to say, you and these questions are bumping my excitement for this interesting game. Can't wait to try it! Good luck!

2 comments

0

I tried this but it still isn't working. Maybe I'm doing something wrong? I placed the script inside ServerScriptService then I placed the GUI in the script. I tried LocalScript and a normal script.

0

I see, Did u put the local script in player? If not, then do that, and if that doesn't work, than place it in this: Game,StarterScripts, and then the StarterPlayerScripts

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