local touchingWater = false local otherPart game.Workspace.TerrainTouched:connect(function(oP) otherPart = oP if oP.Parent == Plr.Character then touchingWater = true end end) game.Workspace.Terrain.TouchEnded:connect(function(otherPart) touchingWater = false end)
This applies for all terrain, but how do I specify only water?
Typed all this on mobile so sorry if anything is weird/inaccurate.
If you want to detect when a player is in water or not, you can use the :GetState() function and the HumanoidStateType enum.
Here is a rough example :
local humanoid = somewhereidk if humanoid:GetState() == Enum.HumanoidStateType.Swimming then print('Swimming') end
In this script, the script checks the state of the humanoid. If it’s swimming, it prints “Swimming”, otherwise it does nothing.
Igoralexeymarengobr’s comment can also work too, but you’ll have to put the parts in every single area filled with water. I would prefer my way if you’re planning on only characters to be detected in water. If you want separate parts to be detected though, you’ll probably have to make the invisible parts, or do something else but I don’t know because I can’t test anything at the moment.
Oh, and if you’re trying to check if any player touches the water, you can make a script like my example and put it in StarterCharacterScripts, or get all the players at once and check if they’re in water or not.
Hope this helped!