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

Maxhealth goes up with leaderstats how?

local Player = game.Players.LocalPlayer
local Maxhealth = Player:WaitForChild('leaderstats'):FindFirstChild('Health')
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

2 answers

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

Players.PlayerAdded:Connect(function(player)
   local char = player.Character or player.CharacterAdded:Wait()

   local Maxhealth = player.leaderstats.Health

   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.

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