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

Keeping gear after death?

Asked by 4 years ago

im trying to make a script that makes it so that you keep a gear after you die but i have no clue how to do it, its meant for a egg hunt event in my own game where you collect eggs and have to get all of them to get a badge award, but when you die you have to get the eggs (they are gears) again.

0
To properly keep items, store them within StarterGear whilst cloning to the Backpack. Ziffixture 6913 — 4y

1 answer

Log in to vote
1
Answered by
14dark14 167
4 years ago
Edited 4 years ago

I remember how I struggled to make this script. I will be nice and give you mine so you don't have to go through everything I had to go trough, it works with R6 and R15. Place the script inside ServerScriptService Make it a ServerScript aka Script not LocalScript

function waitForSpawn(player)
    for i=1,100 do
        if player == nil then return false end
        if player.Character ~= nil and player.Character.Humanoid ~= nil and player.Character.Humanoid.Health ~= 0 then
            return true
        end
        wait(1)
    end
    return false 
end
function die(player, h) 
        if h.Health == 0 then
        local items = {}
        local backpackItems = player.Backpack:getChildren()
        local charItems = player.Character:getChildren()    
        for i=1,#backpackItems do
        table.insert(items, backpackItems[i]:clone())
        end     
        for i=1,#charItems do
        if  (charItems[i].className == "Tool") then
        table.insert(items, charItems[i]:clone())
        end
        end
waitForSpawn(player)
        if player ~= nil then       
        local backpackItems = player.Backpack:getChildren()
        for i=1,#backpackItems do
        backpackItems[i]:remove()
        end     
        local charItems = player.Backpack:getChildren()
        for i=1,#charItems do
            if  (charItems[i].className == "Tool") then
        charItems[i]:remove()
        end
        end     
    for i=1,#items do
        items[i].Parent = player.Backpack
end
end
end
end
function aspawn(character)
    local h = character:findFirstChild("Humanoid")
    if h ~= nil then
        local player = game.Players:playerFromCharacter(character)
        if player ~= nil then
            h.Changed:connect(function () die(player, h) end)
        end
    end
end
game.Workspace.ChildAdded:connect(aspawn)
0
thanks, man! zachmcfly 11 — 4y
0
Every inch of this is wrong Ziffixture 6913 — 4y
0
14dark14 solution is work, but Feahren solution is better. Block_manvn 395 — 4y
0
@Feahren - can you just accept others work? or do you need to be pretentious. I personally think this script is good. your might be a few lines longer than his script but i personally don't like the "I know it all," type of person. He's a beginner and off to a great start. Geez this platform is so toxic maxpax2009 340 — 4y
Ad

Answer this question