Truss pathfinding with a snail

Not sure if the script is the right category, but IDK which one to put this in.

Henlo. I am working on a game about the immortal snail from that one copypasta where you get a ton of money but a snail that kills you if you touch it chases you. I am currently having issues with truss, the poor thing can’t go up them.

Here is a video:

Here is the script:

local runSer = game:GetService("RunService")
local pathFSer = game:GetService("PathfindingService")
local hasTarget = false
local target = nil
local snail = script.Parent

local function findPlayerToKill()
	local nearest = nil
	local nearestDistance = math.huge
	
	for _, v in game:GetService("Players"):GetPlayers() do
		if v.Character and v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Humanoid") then
			local distance = (v.Character.HumanoidRootPart.Position - snail.HumanoidRootPart.Position).Magnitude
			local path = pathFSer:CreatePath({
				AgentRadius = 4,
				AgentHeight = 3,
				AgentCanJump = false,
				AgentCanClimb = true,
				WaypointSpacing = 4,
				Costs = {
					Climb = 0,
					NoSnail = math.huge
				}
			})
			path:ComputeAsync(snail.HumanoidRootPart.Position, v.Character.HumanoidRootPart.Position)

			if path.Status == Enum.PathStatus.Success and distance < nearestDistance then
				nearest = v.Character
				nearestDistance = distance
			end
		end
	end

	if nearest then
		hasTarget = true
		target = nearest
	else
		hasTarget = false
		target = nil
	end
end

runSer.Heartbeat:Connect(function(deltaTime: number)
	if not hasTarget then
		findPlayerToKill()
	else
		if not target or not target:FindFirstChild("HumanoidRootPart") or not target:FindFirstChild("Humanoid") or target.Humanoid.Health <= 0 then
			hasTarget = false
			target = nil
			return
		end
		
		local path = pathFSer:CreatePath({
			AgentRadius = 4,
			AgentHeight = 3,
			AgentCanJump = false,
			AgentCanClimb = true,
			WaypointSpacing = 4,
			Costs = {
				Climb = 0,
				NoSnail = math.huge
			}
		})
		
		path:ComputeAsync(snail.HumanoidRootPart.Position, (target.HumanoidRootPart.Position + target.HumanoidRootPart.Velocity))
		
		if path.Status == Enum.PathStatus.Success then
			local waypoints = path:GetWaypoints()
			for _, waypoint in pairs(waypoints) do
				snail.Humanoid:MoveTo(waypoint.Position)
				snail.Humanoid.MoveToFinished:Wait()
			end
		else
			hasTarget = false
			target = nil
		end
	end
end)

2 Likes

It says I need to request access to see the Google drive video. Try uploading the video directly here or put it up on yt and put the link here if it works.

1 Like

I have fixed the link now lad.

1 Like