Set part size from point A to point B

What I want to do is like a taser script, I’ve got the click event and stuff but I want a part to form from “FirePart” (defined as local fp) to the position of the mouse (defined as mousepos) which is a Vector3.

Example:
The mouse is aiming at this location so it has rotated and positioned itself to the location of the part

It sizes itself so its at the location that the mouse was
image

Cheers.
Note: Briefly read up on some Lerp function, not sure if this would be useful.

2 Likes

You will need to use Lerp for this, Lerp basically finds the point between 2 vector3s, Example Script, which forms a line from PointA to a Player.

    local Part = Instance.new("Part")--Create Part
	Part.Parent = workspace
	Part.Anchored = true
	Part.Size = Vector3.new(15,1,plrdistance)--Distance From Point A to B

    Part.CanCollide = false
	local BaseV3 = player.Character.HumanoidRootPart.Position
    local Point2Position = Vector3.new()
	
	Part.Position = Model.PrimaryPart.Position:Lerp(BaseV3, 0.5)--Moves the part exactly half way between Point A and B
	Part.CFrame = CFrame.new(Part.Position,Point2Position)--Makes Part Look At Point

This isn’t exactly what you asked for but I hope it helps get you started,

1 Like

What is ‘plrdistance’ defined as? Sorry if I’m being dumb.

1 Like
PlayerService.PlayerA:DistanceFromCharacter(Point2Vector3)

This isn’t particularly aiding me here, it won’t always touch a player, could be the floor. I don’t have checks for that.

local fp = --FirePart
local mousepos = --Position of mouse
local plrdistance = (fp.Position - mousepos).Magnitude

Pretty sure it’s this,
Here is how it would be with variables:
(this is @Wizard101fire90 's code, if it works mark their reply as the solution)

local fp = --FirePart
local mousepos = --Position of mouse
local plrdistance = (fp.Position - mousepos).Magnitude

local Part = Instance.new("Part")--Create Part
Part.Parent = workspace
Part.Anchored = true
Part.Size = Vector3.new(15,1,plrdistance)--Distance From Point A to B

Part.CanCollide = false
	
Part.Position = fp.Position:Lerp(mousepos, 0.5)--Moves the part exactly half way between Point A and B
Part.CFrame = CFrame.new(Part.Position,mousepos)--Makes Part Look At Point
2 Likes