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

How do I make a Value not reset it's Value when the player dies?

Asked by 6 years ago

I have tried many ways but I haven't found a way.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Never tested this before, but you could clone a value to a player whenever they first join, and change the value's parent and clone it back to the player whenever the respawn. For example:

--In a Serverscript in ServerScriptService or something

local value = game:GetService("ReplicatedService"):FindFirstChild("Value") --You should change this to wherever you want to store the initial value (Somewhere not in the player)

game:GetService("Players").PlayerAdded:Connect(function(player)
    local valueClone = value:Clone() --Give value to player the first time he/she joins
    valueClone.Parent = player
    player.CharacterAdded:Connect(function(character)
        valueClone.Parent = player; --Parent the value back to the player whenever the character respawns
        character:WaitForChild("Humanoid").Died:Connect(function()
            valueClone.Parent = game.Workspace -- Or anywhere you deem necessary
        end)
    end)
end)

I'm pretty sure something along these lines would work. Hope that helps.

Also, please share the code that you have already tried next time you ask a question in this website. It makes it much easier on us to help you.

Ad

Answer this question