How to add a part to this raycast script?

Hello so i got this part:

while task.wait(1) do
	local whitelistedParts = {
		workspace.PartInBetween;
	}

	local part0 = workspace.Part0
	local part1 = workspace.Part1

	--i subtract the two vectors because traditionally it would look like (part1.Position - part0.Position).Unit * (part1.Position - part0.Position).Magnitude which is just part1.Position - part0.Position

	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Include
	params.FilterDescendantsInstances = whitelistedParts

	local ray = workspace:Raycast(part0.Position, part1.Position - part0.Position, params)
	if ray and ray.Instance then
		print("part is in between")
	else
		print("part is not between")
	end
end

and i was just wondering how can i add a part (laser type thing) so it dissapears when it collides with the wall?

From the official Roblox Tutorial:

function LaserRenderer.createLaser(toolHandle, endPosition)
    local startPosition = toolHandle.Position

    local laserDistance = (startPosition - endPosition).Magnitude
    local laserCFrame = CFrame.lookAt(startPosition, endPosition) * CFrame.new(0, 0, -laserDistance / 2)

    local laserPart = Instance.new("Part")
    laserPart.Size = Vector3.new(0.2, 0.2, laserDistance)
    laserPart.CFrame = laserCFrame
    laserPart.Anchored = true
    laserPart.CanCollide = false
    laserPart.Color = Color3.fromRGB(225, 0, 0)
    laserPart.Material = Enum.Material.Neon
    laserPart.Parent = workspace

    -- Add laser beam to the Debris service to be removed & cleaned up
    Debris:AddItem(laserPart, SHOT_DURATION)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.