How would one tell if a player is under water?

Hi. I want to make a drowning system. I need to detect when the player is swimming and when they’re not, but I can’t figure out how. I can detect when the enter the water, with the Humanoid.Swimming event, but I can’t detect when they stop. Can someone help me? Also, Humanoid:GetState() won’t work, since they player can just jump out of the water.

2 Likes

Create a part that covers the entire water area, and then use ZonePlus to determine if a player is in the water zone or not. This module is great and should help you out.

2 Likes

That sounds a bit tedious. If I would do something like that, I’d just use :GetTouchingParts(). I am looking for a more simple and straight-forward way. Thanks for response, though!

1 Like

Hey there, maybe this could help you:

3 Likes

First of all, don’t use :GetTouchingParts(). It’s broken and trash. ZonePlus is easy to use and has only like 2 functions :OnPlayerEnter() and :OnPlayerLeave(). It’s as easy as that.

1 Like

GetTouchingParts() works, you just need to add a .Touched event to create an interest. But, as I said, since I’m looking for a more effective way, I won’t be using GetTouchingParts() anyways.

Have you tried the solution of the thread I linked?

1 Like

Use GetPartsInPart which does the same except it returns all parts

Also, I don’t really know about it, but it can maybe be a solution Terrain:ReadVoxels I found this read voxels function which returns a table of materials, maybe you can use that

I was just looking at it. I think this may be a good solution. I’ll try it in a minute!

1 Like

You can maybe check if the part is a player, and then get the bounding box of that player, then after you do that you can check all the available materials in such area and if there is a water material then it means the player is touching the water

I’m trying to avoid placing parts for where the water is, because its tedious and the water spaces I have are not spheres or cubes; they’re all twisting. Yes, I’m going to look into using region 3 in a moment. Thanks for your response!

1 Like

Oh! wait I didn’t check that is what the post is suggesting

Why do you need parts? The terrain is a part

1 Like

Because, I have more terrain than just water.

Yes, that is what I am saying, you get the parts in the part, then check if the part is a player. If it is then check the bounding box of that player and check if there is a water material inside the bounding box using ReadVoxels

Yes, I’m going to look into using region 3 in a moment. Thanks for your response!

Yes, I’m going to see if I can use Region3

But like can you clarify, it is because I didn’t really understand. Why don’t you want the GetPartsInPart method?

I said using :GetPartsInParts() is too tedious, because I’d have to make parts and put them in the water.

You can call that function using terrain

1 Like

Again, as I’ve said, all terrain is grouped into one instance called ‘Terrain’, and I have more terrain than just water.

1 Like