Hello! I am trying to make a script that changes a player’s health based on a value. But I am having a couple troubles, the player’s health does not change after death! It still stays at 100 when the value is still at a certain number.
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local player = Players:GetPlayerFromCharacter(character)
local lb = player:FindFirstChild("leaderstats")
lb.Strength.Changed:Connect(function()
if lb.Strength.Value > 1 then
character.Humanoid.MaxHealth = lb.Strength.Value * 2
else
character.Humanoid.Health = 1
character.Humanoid.MaxHealth = 1
end
end)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
I’ve tried moving the script to StarterScripts but no luck. Also tried adding a Died event but still no help.
I think before you have the changed function you have to indicate that the value should equal the humaoid health. Before the lb.Strength.Changed function say lb.Strength.Value = char.Humanoid.Health.