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

Saving tools the player had after death?

Asked by 3 years ago

I have tried something the internet said that the tool should be cloned to the starterPack but it still doesnt work and now i have no clue what i shall do did i miss something

local price = 3 -- The price of your item.
local price2 = 2
local price3 = 1
local db = true

script.Parent.ClickDetector.MouseClick:connect(function(player)
    if player.leaderstats.Wood.Value >= price
        and player.leaderstats.Sticks.Value >= price2 
        and player.leaderstats.String.Value >= price3 then
        player.leaderstats.Wood.Value = player.leaderstats.Wood.Value - price
        player.leaderstats.Sticks.Value = player.leaderstats.Sticks.Value - price2
        player.leaderstats.String.Value = player.leaderstats.String.Value - price3

        db = false
        script.Parent.BrickColor = BrickColor.new("Bright red")
        game.ReplicatedStorage.WoodPickaxe:Clone().Parent = player.StarterPack
        wait(0.5)
        script.Parent.BrickColor = BrickColor.new("Bright green")
        db = true
    end

1 answer

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

Yes, you can clone the tools to the player's StarterPack after death. It would look something like this:

player.Character.Humanoid.Died:Connect(function()
    player.StarterPack:ClearAllChildren()
    for _,tool in pairs(player.Backpack:GetChildren()) do
        tool:Clone().Parent = player.StarterPack
    end
end)

If this does not work for you, what about it is not working? Are there any errors?

EDIT

To address your latest comment, when I said "You will need to have a reference to the player object and make sure the character is not nil too", I meant it.

If you are going to copy and paste the code I provide into an empty script, you will need to do something like this:

game.Players.PlayerAdded:Connect(function(player) -- a reference to the player is added here
    player.CharacterAdded:Connect(function(char) -- making sure a character has been assigned to the player
        char.Humanoid.Died:Connect(function() -- checking for player death
            player.StarterPack:ClearAllChildren()
            for _,tool in pairs(player.Backpack:GetChildren()) do
                tool:Clone().Parent = player.StarterPack
            end
        end)
    end)
end)
0
Where should i put that in thedukke1 9 — 3y
0
A server script. You will need to have a reference to the player object and make sure the character is not nil too archmageofmle 49 — 3y
0
so i just need to put that you have in serverscript service with a script? thedukke1 9 — 3y
0
Yes archmageofmle 49 — 3y
View all comments (3 more)
0
so it says player is an unknown global thedukke1 9 — 3y
0
I updated my answer archmageofmle 49 — 3y
0
thanks a lot for trying but it didnt help i thought you should do something in the shop script thedukke1 9 — 3y
Ad

Answer this question