Weird raycast problem (client)

Hey so I made a raycast shooting from the players HRP to the floor, and from the floor to the object (so basically there’s a line on the floor). And it works perfectly took me a while, but im getting this weird interaction, sometimes it shoots rays sometimes it just stops and I have no idea why

2 Videos, 1 is correct, 1 isn’t (it happens randomly)


Here’s the script (local-sided):

Before the script, fyi i have setup a _G.TrashInstance which works fine, tested it (Trash being the object, and there’s a small part that’s a child of that object which i used for raycasting).

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local arrowPart = ReplicatedStorage.ArrowPart:Clone()
local player = game.Players.LocalPlayer

local char = player.Character or player.CharacterAdded:Wait()
local baseplate = game.Workspace.Baseplate

local p = Instance.new("Part")

local raycastParams = RaycastParams.new()
local raycastResult
local result1

local isAlreadyMade = false

local function makePart(res1, res2, part)

	if res2 and res1 then
		if _G.TrashInstance then
			local distance = (res1.Position - _G.TrashInstance.CircleHolder.Position).Magnitude

			if not isAlreadyMade then
				part.Transparency = 0
				part.Anchored = true
				part.CanCollide = false
				part.Size = Vector3.new(0.1, 0.1, distance)
				part.CFrame = CFrame.lookAt(res1.Position, _G.TrashInstance.CircleHolder.Position) * CFrame.new(0, 0, - distance / 2)
				part.Parent = workspace

				isAlreadyMade = true
			else
				part.CFrame = CFrame.lookAt(res1.Position, _G.TrashInstance.CircleHolder.Position) * CFrame.new(0, 0, - distance / 2)
			end
		else
			isAlreadyMade = false
			part.Transparency = 1
		end	
	end
end

game:GetService("RunService").Heartbeat:Connect(function()
	
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	
	local tabletoignore = {}
	for i, v in pairs(char:GetDescendants()) do
		if v:IsA("Part") or v:IsA("BasePart") or v:IsA("MeshPart") then
			table.insert(tabletoignore, v)
		end
	end
	
	raycastParams.FilterDescendantsInstances = tabletoignore
	
	if _G.TrashInstance then
		
		raycastResult = workspace:Raycast(char.HumanoidRootPart.Position, baseplate.CFrame.UpVector  * -500, raycastParams)
		
		if raycastResult then
			result1 = workspace:Raycast(raycastResult.Position, _G.TrashInstance.CircleHolder.CFrame.lookVector * 5000, raycastParams)
		end		
		
	end
	
	makePart(raycastResult, result1, p)
	
end)

Excuse me for my messy coding, I hope you can find what’s wrong

What’s stopping you from just using a Beam instance to achieve that line effect

oh wow… thanks ill try it later ig