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)
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
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.
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