I'm aware that there is a swimming event for a humanoid, but how do I detect when the humanoid is no longer swimming?
How to check if humanoid is not swimming?
2 answers
#Consulting the APIs
Currently, Humanoids carry an HumanoidStateType Enum that lets you to determine what is the Humanoid doing or how is it behaving. You can check the whole list here
According to the Humanoid API, the humanoid carries a StateChanged() event. It returns two values:
old, that refers to theHumanoidStateTypebefore the event gets triggered
new, that refers to theHumanoidStateTypethat applies currently to the Humanoid.
#The Final Result
So, as you want to find out when an humanoid stops swimming, it should be obvious that you might want to search for the old value the event returned, so the final script would be:
script.Parent.Humanoid.StateChanged:connect(function(old, new) -- assuming that your script is inside the character.
if old == Enum.HumanoidStateType.Swimming then
-- paste code there
end
end)
Hope I helped! If yes, do not forget to accept my answer.
I think there may be a way to do that but a way you COULD do is by creating a part that is on the water and make a script in the part that uses the 'TouchEnded' event. With the event, it checks if you have stopped touching the part.
This discussion is preserved as it was. New answers, comments, and votes are closed.
