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

How come the backpack items don't reappear when the player respawns?

Asked by 8 years ago

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)

1 answer

Log in to vote
1
Answered by 8 years ago

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)

0
Thank you Hungryjaffer! Legobrain9275 25 — 8y
0
StarterGear is a child of Player, which is only present when a player is in game. HungryJaffer 1246 — 8y
Ad

Answer this question