Player gets kicked when IntValue reaches 0?!

Howdy DevForum members! I am trying to make this simple script so that when this IntValue reaches 0 the player gets kicked. This is what I have currently.

if script.Parent.HungerAmount.Value == 0 then
	script.Parent.Parent.Parent.Parent.Parent:Kick("Your pet died!")
end

I am not sure if this is the correct way because I am not much of a scripter.

You need to check when it changes, right now you’re just checking once if it equals 0, then never again.

script.Parent.HungerAmount.Changed:Connect(function()
    if script.Parent.HungerAmount.Value == 0 then
	    script.Parent.Parent.Parent.Parent.Parent:Kick("Your pet died!")
    end
end)

Thank you so much! This helps a lot and teaches me, I am learning Values currently, this helped so much and taught me a bit. Thank you.

4 Likes
Value.Changed:Connect(function(NewValue)
	if NewValue == 0 then Player:Kick() end
end)

The connected callback function is passed the value object’s new value (when its ‘Changed’ event/signal is fired).