Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to draw a line on a path, between Start and End points?

I am trying to find out how to make/draw a line between a start and end point of a character path. Similar to what they do in the Pet Simulator game. When you click on the coins, the Pet uses a WalkToPoint (or something similar), and moves towards the coin. I know how to do that, but in that game, there is a cool line that is drawn to show the path. Also there is a circle underneath the pet (current Position) and one underneath the coin (target Position).

Does anyone know how to code to draw that line (dots in this case)? Or can you point me to some tutorial or documentation, please?

I have looked a lot already, learned a little about Pathfinding, NavMesh, but I couldn't find much, if anything, about drawing the path.

I found a way to do it with creating Parts, but I would rather have it displaying as a dotted line like the Pet Simulator game.

Thanks!

-- Make variables for Roblox services
local PathfindingService = game:GetService("PathfindingService")
 
-- Make variables for the start and end of the path
local start = Vector3.new(0, 1, 0)
local finish = Vector3.new(25, 1, -60)
 
-- Find the path and get the waypoints
local path = PathfindingService:FindPathAsync(start, finish)
local waypoints = path:GetWaypoints()
 
-- Loop through all of the waypoints in the path
for waypointIndex, waypoint in pairs(waypoints) do
	-- Create a part for each waypoint and position the part
	-- at the waypoint's position.
	local part = Instance.new("Part")
	part.Size = Vector3.new(1, 1, 1)
	part.Position = waypoint.Position
	part.CanCollide = false
	part.Anchored = true
	part.Parent = game.Workspace
end

1 answer

If you just want to draw a straight line from your character to a part (example) then you can just use a beam. Create an attachment in the part where you want it, and an attachment from where you want it from.

Then in the Beam's properties, set Attachment0 and Attachment1 to the attachments and it will create a line between. You can change other properties of the beam to make it look different.

Hope this helped

This discussion is preserved as it was. New answers, comments, and votes are closed.