Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Maxhealth goes up with leaderstats how?

Asked by 3 years ago
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

Log in to vote
1
Answered by 3 years ago
Edited 3 years 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")

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.

Ad
Log in to vote
0
Answered by 3 years ago

Try to Change your Health value first

Answer this question