Need help with stats is not a valid member of noobforlifeisanoob

Hi I added it so that it waits for the character to load but sometimes it does not make the characters health to players level MaxHealth It sometimes say that player.Stats is not a valid member of noobforlifeisanoob which is really annoying considering that sometimes it work sometimes it does not so heres the script

 local Players = game:GetService("Players")
> 
> function updateMaxHealth(player)
> 	local level = player.Stats.Level.Value
> 	local maxHealth = 100
> 
> 	if level == 20 then
> 		maxHealth = 2500
> 	elseif level == 19 then
> 		maxHealth = 1500
> 	elseif level == 18 then
> 		maxHealth = 950
> 	elseif level == 17 then
> 		maxHealth = 800
> 	elseif level == 16 then
> 		maxHealth = 750
> 	elseif level == 15 then
> 		maxHealth = 723
> 	elseif level == 14 then
> 		maxHealth = 650
> 	elseif level == 13 then
> 		maxHealth = 600
> 	elseif level == 12 then
> 		maxHealth = 550
> 	elseif level == 11 then
> 		maxHealth = 500
> 	elseif level == 10 then
> 		maxHealth = 450
> 	elseif level == 9 then
> 		maxHealth = 400
> 	elseif level == 7 then
> 		maxHealth = 350
> 	elseif level == 6 then
> 		maxHealth = 300
> 	elseif level == 5 then
> 		maxHealth = 250
> 	elseif level == 4 then
> 		maxHealth = 200
> 	elseif level == 3 then
> 		maxHealth = 150
> 	end
> 
> 	player.Character.Humanoid.MaxHealth = maxHealth
> end
> 
> Players.PlayerAdded:Connect(function(player)
> 	player.CharacterAdded:Connect(function(character)
> 		player.Stats:WaitForChild("Level")
> 
> 		updateMaxHealth(player)
> 	end)
> 
> 	player.Stats.Level.Changed:Connect(function()
> 		updateMaxHealth(player)
> 	end)
> end)

You’re assuming that Stats exists and is parented to player, which given the error, is not always true. You need to use WaitForChild here.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.