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

How do I check if a player is swimming without using the .Swimming event?

Asked by 8 years ago

Upon learning that the .Swimming event would not trigger while the Humanoid was in the PlatformStand state, I immediately began to seek a way around this. So, I came to the idea that the GetCell function would help, but it did not. I needed a way to determine whether the player was in water or not.

local PX,PY,PZ=Character.Torso.Position.x,Character.Torso.Position.y,Character.Torso.Position.z
local CM,CB,CO=game.Workspace.Terrain:GetCell(PX,PY,PZ)
print(PX,PY,PZ)
print(CM)
if CM == Enum.CellMaterial.Empty then
    print("EmptySpace")
end

Please note the above script was ran every frame, using a LocalScript. This was the constant output taken from the GetCell function.

Enum.CellMaterial.Empty
Enum.CellBlock.Solid
Enum.CellOrientation.NegZ

--Edit, I used GetWaterCell after finding it on the wiki and changed my script to fit the new function. vvvvvvvv

local PX,PY,PZ=Character.Torso.Position.x,Character.Torso.Position.y,Character.Torso.Position.z
local hasWater,waterForce,waterDirection=game.Workspace.Terrain:GetWaterCell(PX,PY,PZ)
print(hasWater,waterForce,waterDirection)
if hasWater then
    print("EmptySpace")
end

Output:

false Enum.WaterForce.None Enum.WaterDirection.NegX
1
I believe you need to use WorldToCell method. Read about it here: http://wiki.roblox.com/index.php?title=API:Class/Terrain/WorldToCell Lacryma 548 — 8y
0
The point is to transfer the character's position to cell units. Lacryma 548 — 8y
0
Thanks for this, I'll try it out xolbStudios 127 — 8y

Answer this question