Having trouble with a water script

So, I found and heavily edited a water script to sort of mimic terrain water in part form, and i’m having some trouble getting rid of some bugs. One bug, is presumably because of the debounce when touching the water, which causes the animation not to run all the way through, but keep repeating constantly, and i’m not sure how to change the debounce and still make it so the water constantly detects players. Another bug is that you can sometimes fly outside of the water, even though there is a check if the player left the water. I have no clue what’s causing this as there’s no error, so it might also be a debounce thing, not sure though.

I would post the code, but it’s about 170 lines long, and this is already TL;DR lol.
Here is the code so you can see it for yourself, and test it out:
WaterTest.rbxl (24.6 KB)

Here is a gif of the problem:
https://gyazo.com/2c8b7e5143fade634c7c4abef7f1e68c

If you need any more information, don’t hesitate to ask me!
Help would be appreciated! Thank you!

Quick pointer that will help you with this and other issues:

Always, always separate your animations from your actions. There should be code responsible for detecting whether the user is swimming, and then seperate code that uses the detector to apply animations.

So should I run it through a event, just like I did with the plane detection? I’ve never really worked with animations so I don’t really know how to implement them.

I looked at your code and I think I fixed the problem. Here’s the file
WaterTest.rbxl (24.6 KB)
The script before loaded the animation every time the player began swimming and never stopped it. You should always load an animation once and then Play/Stop it whenever you need to

I added the line local playAnim = Human:LoadAnimation(anim) at the top and added playAnim:Play() and playAnim:Stop() when the player starts/stops swimming

The animation won’t play anymore when touching the water.
https://gyazo.com/926020c8d4afcb1d5c1cae9b080fa6cd

By animation I mean any kind of user-facing effect, like the GUI turning blue.

OOPS! I accidentally forgot to check the playAnim.IsPlaying property before playing/stopping the playAnim
I also changed Torso.Touched to Root.Touched to simplify things since you already wrote in your code Root.TouchEnded
WaterTestFix.rbxl (24.6 KB)
Tried this with my animations and it works fine.
If it still doesn’t work, make sure your swimming animation priority is set to a higher one (e.g. Action)
Hope this helped!

So strange. It works fine when you enter the water from the top, but if you enter the water from the side, and go up, it will randomly stop the animation.

Going from the side up:
https://gyazo.com/1aabc8cbf9faedcbfeb08cc4c62099f2
From the top:
https://gyazo.com/2077c997cdff002137c4dd96dad443da

Nonetheless, thank you for the help!

1 Like

That’s good to hear! At the end I’d suggest you changing your animation priority to Action so that the jump and fall animation don’t overlap the swimming animation. I believe that the jump/fall animation overlapping the swimming animation is the reason why it’s strange going from the side up

1 Like

Ah I see. Thank you :slight_smile:

1 Like