- 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.
- 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.
- 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)