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)
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
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)
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
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!