Fish system not floating when unanchored

  1. What do you want to achieve? Keep it simple and clear!

I want to make a server script that spawn fish in a loop that go to random waypoints.

  1. What is the issue? Include screenshots / videos if possible!

The issue is that the fish is constantly falling into the void, so every child/basepart of the fish except the humanoid is being deleted. The script is working when I apply cancollide to all the fish’s parts, but the fish aren’t actually swimming in the water, they’re just hovering over it.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried redoing this in a much smaller script but my new script came with the same result. I had previously welded my fish using the studio constraints editor using welds.

Simplified script:

local SS = game:GetService("ServerStorage")
local spawns = SS.Spawns
local workspacespawnstable = {
	workspace:WaitForChild("Spawns").Spawn1,
	workspace:WaitForChild("Spawns").Spawn2,
}

local waypointstable1 = {
	workspace:WaitForChild("FishWaypoints1")["1"],
	workspace:WaitForChild("FishWaypoints1")["2"],
	workspace:WaitForChild("FishWaypoints1")["3"],
}
local waypointstable2 = {
	workspace:WaitForChild("FishWaypoints2")["1"],
	workspace:WaitForChild("FishWaypoints2")["2"],
	workspace:WaitForChild("FishWaypoints2")["3"],
}

local function movefish(waypointstable, humanoid, taken)
	local debounce = false
	repeat
		local randomwaypoint = math.random(1,#waypointstable)
		local chosenwaypoint = waypointstable[randomwaypoint]
		if not debounce then
			debounce = true
			humanoid:MoveTo(chosenwaypoint.Position)
			humanoid.MoveToFinished:Connect(function(achieved)
				if achieved then
					debounce = false
				end
			end)
		end
		task.wait(1)
	until taken == true
end

local function coreloop()
	while task.wait(10) do
		local random = math.random(1,#workspacespawnstable)
		local chosen = workspacespawnstable[random]
		local newfish = spawns.Fish:Clone()
		local takenboolean = newfish:GetAttribute("Taken")
		newfish.Parent = workspace
		newfish:MoveTo(chosen.Position)
		if random == 1 then
			task.spawn(movefish,waypointstable1, newfish.Humanoid,takenboolean)
		elseif random == 2 then
			task.spawn(movefish,waypointstable2, newfish.Humanoid,takenboolean)
		end
	end
end

task.spawn(coreloop)
1 Like

I’m gonna assume that you’re trying to make the fish float. I think you can just add a BodyForce (though deprecated, newer one: VectorForce) to make the fish cancel the workspace gravity.

Apply sufficient amount of force on the y-axis (F = mg, where F = force, m = mass, g = gravity)
VectorForce - Roblox

2 Likes

I forgot to mention but the force formula might be inaccurate. I don’t know if Roblox has air resistance and other motion-related variables, so adjust accordingly

1 Like

I’m gonna try to look more into vectorforce.

newfish.VectorForce.Force = Vector3.new(0,workspace.Gravity * newfish.HumanoidRootPart.AssemblyMass,0)

Explorer:
help

The fish aren’t falling in void now but they are slowing ascending.

I just had to use assemblycenterofmass!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.