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

Why does my script that a player's max heath depends on leaderstats not work?

So I'm trying to make a script to where a player's max heath is increased by a leaderstat. For example, if a player was level 20, their heath would be 120. But the script I made isn't working. Here is the script :

game.Players.PlayerAdded:Connect(function(plr)
	
	plr.CharacterAdded:Connect(function(chr)
		local hum = chr:WaitForChild("Humanoid",)
		local leaderstats = plr:WaitForChild("leaderstats")
		local Kaze = leaderstats:WaitForChild("Kaze")
		repeat wait() until plr:FindFirstChild("DataLoaded")~=nil
		hum.MaxHealth = Kaze.Value +100
		hum.Health = hum.MaxHealth
	end)
	

end)

Please help me out.

1 answer

You have a comma on line 4 that you shouldn't have (second last character on that line).

You can catch errors like that with the script analysis and output windows.

If that syntax error isn't in the original script, I recommend putting a print statement on every line to determine which lines are working - ex, if DataLoaded never appears, the script wouldn't appear to do anything; a print statement would help you discover this.

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