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

(NEED HELP) Humanoid Saving stats on dead ?

Asked by 6 years ago
Edited 6 years ago

I want to make a store like that when a player buys 4 health points and instead of being at 100 he will get 104 but the problem is that I want him to stay the same when the player dies and reappears because I noticed that when I die my character remounts to 100 instead of 104 of life

    game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        chr:WaitForChild("Humanoid").Died:connect(function()
            print(plr.Name.." is Dead")
            local hum = chr.Humanoid
            wait(.5)
            hum.WalkSpeed = chr.Humanoid.WalkSpeed
        end)
    end)
end)

2 answers

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Set their Humanoid's MaxHealth each time they respawn.

local function GetHealthForPlayer(plr)
    -- do stuff here to check what amount of max health the player should have
end

game:GetService("Players").PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        char:WaitForChild"Humanoid".MaxHealth = GetHealthForPlayer(plr)
    end)
end)
Ad
Log in to vote
0
Answered by 6 years ago

Should help:

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        chr:WaitForChild("Humanoid").Died:connect(function()
            print(plr.Name.." is Dead")
            local hum = chr.Humanoid
            local OldMax = hum.MaxHealth -- This won't change
            plr.CharacterAdded:Connect(function()
                plr.Character.MaxHealth = OldMax
                plr.Character.Health = OldMax
            end)
        end)
    end)
end)

I noticed you also wanted to keep the player's WalkSpeed. Use this instead if so:

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        chr:WaitForChild("Humanoid").Died:connect(function()
            print(plr.Name.." is Dead")
            local hum = chr.Humanoid
            local OldMax = hum.MaxHealth -- This won't change
            local OldSpeed = hum.WalkSpeed -- This also won't change
            plr.CharacterAdded:Connect(function()
                plr.Character.MaxHealth = OldMax
                plr.Character.Health = OldMax
                plr.Character.WalkSpeed = OldSpeed
            end)
        end)
    end)
end)

Answer this question