✓ Accepted answer
The problem here is that the Jumping event fires when the character starts jumping and when the character has landed. In order to fix this, check whether or not the active parameter passed through the event is true.
local plr = game.Players.LocalPlayer
plr.Character.Humanoid.Jumping:Connect(function(active)
if active then
thirstValue.Value = thirstValue.Value - 1
end
end)
Alternatively, you can use the StateChanged event. Not only does it fix your problem, it's also way more flexible.
local plr = game.Players.LocalPlayer
plr.Character.Humanoid.StateChanged:Connect(function(oldState , newState)
if newState == Enum.HumanoidStateType.Jumping then
thirstValue.Value = thirstValue.Value - 1
end
end)
The function first checks whether or not the newState parameter is the Jumping state. Then, it decrements thirstValue by one.
1 comment
Perfect. Thanks for the explanation.