I am making a game where i want the fish to swim, I made this script for animals on the land and it works but when I added it onto the fish, the fish sink down, can anyone help me make it so the fish can swim like the player in the water?
local pathfindingservice = game:GetService("PathfindingService")
local act = true
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
while wait() do
if act == true then
act = false
math.randomseed(tick()%1*1e6)
local items = workspace.WaterPathFindingWaypoints:GetChildren()
local destination = items[math.random(1, #items)]
local path = pathfindingservice:CreatePath()
path:ComputeAsync(body.Position, destination.Position)
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end
end
wait(math.random(2,15))
act = true
end
