I can not update ray every moment?

Uh i am trying to make a raycast thing for testing, and i need to keep ray updated every moment. How do i do that?

I tried while loops, runservice. But they didnt work.

(I copied a code that makes ray visible from a video so i can see it isn’t updating)

1 Like

This might be an issue with your implementation. You can definitely setup a raycast within both a while loop (rate ~= 1/30) and within the runservice (rate ~= 1/60). Maybe some code could help us debug?

local radius = 1

local function MakeRayVisible(ray)
	local midpoint = ray.Origin + ray.Direction/2
	
	local part = Instance.new("Part")
	
	part.Parent = workspace
	part.Anchored = true
	part.CFrame = CFrame.new(midpoint, ray.Origin)
	part.Size = Vector3.new(radius, radius, ray.Direction.magnitude)
	part.Material = Enum.Material.Neon
	part.BrickColor = BrickColor.new("Medium red")
	
	return part
	
end



local part = script.Parent

local origin = part.Position

local direction = part.CFrame.LookVector * 10

local ray = Ray.new(origin, direction)
	MakeRayVisible(ray) 
	


(without loop)

The loop is kind of essential to me helping you figure out why the loop isn’t working

Can’t you just do runservice.RenderStepped and not make it a function but instead write the code in the runservice.RenderStepped