Ad
Log in to vote
-1

Would this work? (Cloning weapons once Player dies script)

Asked by 7 years ago

How can I make it so if someone buys a weapon using In game currency at my dialog shop that if they die they keep it? Could this script part below work if I add the locals and such? Also is this part correct as a body of the script ( I will declare the locals and more ) if Player.Health = 0 then Weapon1.ReplicatedStorage.Clone() Well I could use some tips to make this script work. Thank you.

2 answers

Log in to vote
0
Answered by 7 years ago

insert a script and put in workspace, when you die, you will respawn with your tools

function saveWeapons(player)
    local bin = Instance.new("HopperBin")
    bin.Parent = game.Lighting
    bin.Name = player.Name
    local stuff = player.Backpack:GetChildren()
    for i = 1,#stuff do
        local name = stuff[i].Name
        if game.StarterPack:findFirstChild(name)==nil then
            stuff[i]:Clone().Parent = bin
        end
    end
    local char = player.Character:GetChildren()
    for i = 1,#char do
        if char[i].className == "Tool" then
            local name = char[i].Name
            if game.StarterPack:findFirstChild(name)==nil then
                char[i]:Clone().Parent = bin
            end
        end
    end
end

function onRespawned(player)
    local findBin = game.Lighting:findFirstChild(player.Name)
    if findBin~=nil then
        local stuff = findBin:GetChildren()
        for i = 1,#stuff do
            stuff[i]:Clone().Parent = player.Backpack
        end
        findBin:Remove()
    end
    player.Character.Humanoid.Died:connect(function()
        saveWeapons(player)
    end)
end

function onPlayerEntered(newPlayer)
    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
            onRespawned(newPlayer)
        end
    end)
    while true do
        if newPlayer.Character~=nil then break end
        wait()
    end
    newPlayer.Character.Humanoid.Died:connect(function()
        saveWeapons(newPlayer)
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)
0
Thanks! coldice231 45 — 7y
0
My only problem is that my game has a lobby and I don't want people killing in the lobby. coldice231 45 — 7y
Ad
Log in to vote
4
Answered by 7 years ago

Place the gear into the Player's StarterGear and into their Backpack when they purchase the gear. After that, they will spawn with the gear every time until they leave.

0
Like clone it into their StarterGui? coldice231 45 — 7y
0
No, clone it into the Player's Backpack when they first buy it, and also clone it into the Player's StarterGear when they first buy it. They will then spawn with that gear every time. Articulating 1330 — 7y

Answer this question