just do this:
add a remote event in replicated Storage then from a local script you should listen for changes in player's strength leaderstat, when there is a change in strength leaderstat then call the remote event so the server can update the player's max health;
example:
-- in local script
local inc_Health = game.ReplicatedStorage.updateHealth
local player = game.Players.LocalPlayer
local strength = player.leaderstats.Strength
strength.GetPropertyChangedSignal("Value"):Connect(function()
inc_Health:FireServer(strength.Value)
end)
--in server script
the following code adds 5 health to the players max health every time their strength increase.
to make it so the player only gets 50 health every ten times that the player's health increase then see the next code example
local inc_Health = game.ReplicatedStorage.updateHealth
inc_Health .OnServerEvent:Connect(function(player,value)
local char = player.Character
local humanoid = char.Humanoid
humanoid.MaxHealth = 100+(5*value)
humanoid.Health = Humanoid.MaxHealth
end)
to make it so the player only gets 50 health every ten times that the player's health increase
-- in server script
local inc_Health = game.ReplicatedStorage.updateHealth
inc_Health .OnServerEvent:Connect(function(player,value)
local char = player.Character
local humanoid = char.Humanoid
if value==0 then
humanoid.MaxHealth = Humanoid.MaxHealth + 50
humanoid.Health = Humanoid.MaxHealth
end
end)
4 comments
Wow thank you very much, it worked perfectly. And more importantly, thanks for helping me understand what you've done here as well, it's very much appreciated! :D
only the local player will see the health change but not everyone else in the game
yeah I should've realized that @Arsubai12 oops
I've also realised that my script for leveling the player, as he reaches the needed XP is only client sided. So the level in the server's leaderstats is still at level 1. Should I try and do the same thing with a remote event, for increasing the player's level as well?