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 6 years ago

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)
0
switch to :Clone(). clone() was deprecated User#19524 175 — 6y
0
That didn't fix it :( Michael_TheCreator 166 — 6y
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 — 6y
0
Thank you Michael_TheCreator 166 — 6y

4 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 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

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

0
Put this in Game>StarterScripts>StarterPlayerScripts User#17125 0 — 6y
Ad
Log in to vote
1
Answered by
LuaDLL 253 Moderation Voter
6 years ago
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)

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 — 6y
Log in to vote
0
Answered by 6 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.

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

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

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!

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 — 6y
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 — 6y

Answer this question