Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

(NEED HELP) Humanoid Saving stats on dead ?

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

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)

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.