Why does the value change constant.ly when i die?

game:GetService("Players").PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function(character)
		while true do 
			wait(0.5)
			local torso = character:WaitForChild("Torso")
			player.leaderstats.Height.Value = math.ceil(torso.CFrame.y)/8
		end
	end)
end)

thats the script, it keeps going to the value it did before i died

Because the loop doesnt stop when you respawn. Its also a memory leak.

Here:

game:GetService("Players").PlayerAdded:Connect(function(player)
local updateValue
	player.CharacterAdded:Connect(function(character)
		if updateValue then task.cancel(updateValue) end
		updateValue = task.spawn(function()
			while true do 
			task.wait(0.5)
			local torso = character:WaitForChild("Torso")
			player.leaderstats.Height.Value = math.ceil(torso.CFrame.y)/8
		end
		end)
	end)
end)

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