Why doesn't this script clone the Gui to PlayerGui? How can this be fixed?
Code:
01 | game.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 ) |
14 | end ) |
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
01 | plr = 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 |
13 | wait( 5 ) |
14 | LevelUpCongrats:Destroy() |
15 | end ) |
16 | end ) |
Also I added a part to destroy the notification after 5 sec. Remove if you want
01 | game.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 ) |
14 | end ) |
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.
01 | local SS = game:GetService( "ServerStorage" ) |
02 | local LevelUp = SS:WaitForChild( "LevelUpCongrats" ) |
03 |
04 | game.Players.PlayerAdded:Connect( function (plr) |
05 |
06 | local 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 ) |
19 | 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
Hey, Professional_Lua beat me to it, but on line 12 change the
1 | LevelUpCongrats.Parent = plr.PlayerGui |
to
1 | 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!