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)
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)