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

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

Asked by 7 years ago

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

Code:

01game.Players.PlayerAdded:Connect(function(plr)
02 
03    local LSystem = plr:WaitForChild("LevelSystem")
04    local PStats = plr:WaitForChild("PlayerStats")
05    local level = LSystem:WaitForChild("Level")
06    local points = PStats:WaitForChild("Points")
07 
08    level.Changed:Connect(function(val)
09        points.Value = 0
10        repeat wait () until plr.Character
11    local LevelUpCongrats = script.LevelUpCongrats:clone()
12    LevelUpCongrats.Parent = plr.PlayerGui
13    end)
14end)
0
switch to :Clone(). clone() was deprecated User#19524 175 — 7y
0
That didn't fix it :( Michael_TheCreator 166 — 7y
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 LeaderAssassinNinja 69 — 7y
0
Thank you Michael_TheCreator 166 — 7y

4 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

01plr = game.Players.LocalPlayer
02    local LSystem = plr:WaitForChild("LevelSystem")
03    local PStats = plr:WaitForChild("PlayerStats")
04    local level = LSystem:WaitForChild("Level")
05    local points = PStats:WaitForChild("Points")
06 
07    level.Changed:Connect(function(val)
08        points.Value = 0
09        repeat wait () until plr.Character
10    local LevelUpCongrats = script.LevelUpCongrats:Clone()
11    LevelUpCongrats.Parent = plr.PlayerGui
12-- Extra Bit
13wait(5)
14LevelUpCongrats:Destroy()
15    end)
16end)

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

0
Put this in Game>StarterScripts>StarterPlayerScripts User#17125 0 — 7y
Ad
Log in to vote
1
Answered by
LuaDLL 253 Moderation Voter
7 years ago
01game.Players.PlayerAdded:Connect(function(plr)
02 
03    local LSystem = plr:WaitForChild("LevelSystem")
04    local PStats = plr:WaitForChild("PlayerStats")
05    local level = LSystem:WaitForChild("Level")
06    local points = PStats:WaitForChild("Points")
07 
08    level.Changed:Connect(function(val)
09        points.Value = 0
10        repeat wait () until plr.Character
11    local LevelUpCongrats = script.LevelUpCongrats:Clone()
12    LevelUpCongrats.Parent = plr:WaitForChild("PlayerGui")
13    end)
14end)
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. Michael_TheCreator 166 — 7y
Log in to vote
0
Answered by 7 years ago

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.

01local SS = game:GetService("ServerStorage")
02local LevelUp = SS:WaitForChild("LevelUpCongrats")
03 
04game.Players.PlayerAdded:Connect(function(plr)
05 
06local plrgui = plr:WaitForChild("PlayerGui")
07    local LSystem = plr:WaitForChild("LevelSystem")
08    local PStats = plr:WaitForChild("PlayerStats")
09    local level = LSystem:WaitForChild("Level")
10    local points = PStats:WaitForChild("Points")
11 
12 
13    level.Changed:Connect(function(val)
14        points.Value = 0
15        repeat wait () until plr.Character
16    local levelgui = LevelUp:Clone()
17    levelgui.Parent = plrgui
18    end)
19end)

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

0
I'm not sure what I'm doing wrong but it still isn't working? Michael_TheCreator 166 — 7y
0
Did you put the GUI in ServerStorage and the Script in ServerScriptService? LukeGabrieI 73 — 7y
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

1LevelUpCongrats.Parent = plr.PlayerGui

to

1LevelUpCongrats.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!

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. Michael_TheCreator 166 — 7y
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 LeaderAssassinNinja 69 — 7y

Answer this question