Model gets flung off the face of the earth

I’m making a fish that swims randomly around using path finding service. But for some reason whenever I start the game to test it the parts in the fish’s Y position just gets set to some crazy negative number and get deleted from workspace. I would like to know if anyone knows the solution to this!

Even when anchored it’s sent to the negatives, but not deleted.

Maybe it has something to do with the fish script I saw in the output. Try posting the script in scripting support

2 Likes

The error is saying it can’t find the fishes HumanoidRootPart because of it getting deleted.

Yes, but there’s probably something in the script that’s setting the waypoint to some weird number.
The Output print statement says it’s setting the waypoint for a second time before the error, but then you get the Humanoid error after it disappears.
Post the script with 3 backticks (```) in front of and behind it so we can see it here.

Sorry, I had to go for a bit. But I’m back now

local fish = script.Parent
local humanoid = fish.Humanoid

while wait(3) do
	humanoid:MoveTo(Vector3.new("-"..math.random(442, 2358), math.random(1455, 1552), math.random(126, 380)))
	
	local PathfindingService = game:GetService("PathfindingService")
	local fish = script.Parent
	local humanoid = fish.Humanoid
	local destination = humanoid.WalkToPoint
	local path = PathfindingService:CreatePath()
	path:ComputeAsync(fish.HumanoidRootPart.Position, destination)
	local waypoints = path:GetWaypoints()
	
	for _, waypoint in pairs(waypoints) do
		print("Making Waypoint")
		local part = Instance.new("Part")
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Size = Vector3.new(0.8, 0.8, 0.8)
		part.Position = Vector3.new(waypoint.Position.X, fish.HumanoidRootPart.Position.Y, waypoint.Position.Z)
		part.Anchored = true
		part.CanCollide = false
		part.Transparency = 0
		part.Parent = game.Workspace
		
		--fish.Body.CFrame = CFrame.new(fish.HumanoidRootPart.Position, part.Position)
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
		part:Destroy()
	end
end

I have found that disabling the “fish.Body.CFrame = CFrame.new(fish.HumanoidRootPart.Position, part.Position)” Makes the fish not teleport away, but I have no idea why this would cause problems. (It’s to change the fishes lookvector for clarification)

Hey, since this is scripting related, would advice you to put it in #help-and-feedback:scripting-support so other scripters can help you out! :grinning_face_with_smiling_eyes: