Problems with a part swimming system

I have been trying to make a part swimming system, and I have the script below so far. The problem is,
when the character stops moving, they fall to the ground abruptly, instead of floating in the water. Also, if you hold w when moving out of the water, you’ll keep swimming on the ground. Look at this video for a visual explanation:

local water = game.Workspace.WaterParts.water

water.Touched:Connect(function(hit)
	local plr = hit.Parent:FindFirstChild("Humanoid")
	if plr then
		plr:SetStateEnabled("GettingUp", false)
		plr:ChangeState("Swimming")
	else
		plr:ChangeState(Enum.HumanoidStateType.Running)
	end
end)

2 Likes

This is caused by gravity. You’d need to use a BodyForce which would play as anti-gravity against this.
Script to calculate how much force you’d need.

local Part = script.Parent
local ForceValue = (workspace.Gravity * Part:GetMass())

These 2 videos go into a lot of detail about this, I highly suggest watching them:

5 Likes

I’ll watch those, thanks for the reccomendation.

1 Like