0

# Maxhealth goes up with leaderstats how?

local Player = game.Players.LocalPlayer
local char = script.Parent

Maxhealth.Changed:Connect(function()
char:WaitForChild('Humanoid').MaxHealth = Maxhealth.Value
end)


so this is my script Health is the leaderstat and its a local script ind starter character script the script isnt working so did i do something wrong

1
Edited 1 year ago

Problem

Changing MaxHealth in a LocalScript will only be visible to you. I can see why you used a LocalScript to get the LocalPlayer, but you can use the PlayerAdded event with the PlayerThatWasAdded parameter in a Script.

I think you need to understand the client-server model.

Recommendations

You should use :GetPropertyChangedSignal("Property-name") because you're only using the Value property.

Always use :GetService() even if you can define it in the explorer. This is just in case if you change the name of the service.

Fixed Script

local Players = game:GetService("Players")

local char = player.Character or player.CharacterAdded:Wait()

Maxhealth:GetPropertyChangedSignal("Value"):Connect(function()
char.Humanoid.MaxHealth = Maxhealth.Value
end)
end)


Make sure it's a Script and not a LocalScript and put the Script in ServerScriptService.