Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make terrain water detection?

Asked by
Macbane 46
5 years ago
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?

0
Is TerrainTouched even an event of Workspace? Never seen it in the API. User#19524 175 — 5y
0
oh sorry it's suppose to be Terrain.Touched. I was trying stuff like Terrain.Water.Touched just for the heck of it. When I deleted Water, I deleted the "." too. Macbane 46 — 5y
0
There is no specific event for touching water. As far as I know, Terrain Touched and TouchEnded don't do anything. Thundermaker300 554 — 5y
0
There is no but you can put a invisible part without collision on the water so maybe would work with OnTouched Igoralexeymarengobr 365 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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!

0
thank you! Macbane 46 — 5y
Ad

Answer this question