I am a beginner scripter and I have been working on this script. It is supposed to add more gear to the players backpack every time they level up, and that part works, but when they die none of the gear respawns. I tried solving it with the character:WaitForChild("Humanoid").Died:connect(function() in order reset the lev0 variable to false, but that didn't seem to work. The real script is larger, with 10 different functions for 11 levels, but I only included the lev0 function to make it easier to read. Please help me!
game.Players.PlayerAdded:connect(function(player) wait(2) local stats = player.leaderstats.Level.Value local alive = true local lev0 = false player.CharacterAdded:connect(function(character) alive = true character:WaitForChild("Humanoid").Died:connect(function() alive = false lev0 = false end) end) while stats and alive == true do if stats >= 0 and lev0 == false then local flashlight = game.ServerStorage.Flashlight:Clone() flashlight.Parent = player.Backpack lev0 = true end end end)
If we want the player to respawn with the tool, we must also put it into their startergear. Startergear
is a folder inside the player that clones its children into the player's backpack every time the player dies.
game.Players.PlayerAdded:connect(function(player) wait(2) local stats = player.leaderstats.Level.Value local alive = true local lev0 = false player.CharacterAdded:connect(function(character) alive = true character:WaitForChild("Humanoid").Died:connect(function() alive = false lev0 = false end) end) while stats and alive == true do if stats >= 0 and lev0 == false then local flashlight = game.ServerStorage.Flashlight:Clone() flashlight.Parent = player.Backpack flashlight.Parent = player.StarterGear lev0 = true end end end)