What do I put here?

Hey guys. I was working on making a raycast that would print whatever object it touched, but I don’t know much about raycasting. Mind helping me out? If not, thanks a bunch!

local function CreateRay()
	local WorkSpace = game:GetService("Workspace")
	local Camera = Workspace:FindFirstChild("Camera")
	local Baseplate = Workspace:FindFirstChild("Baseplate")
	if Camera and Baseplate then
		local RayParams = RaycastParams.new()
		RayParams.RespectCanCollide = true
		local Raycast = WorkSpace:Raycast(Camera.Focus.Position, game.Workspace.Baseplate.Position, RayParams.RespectCanCollide)
		-- Not sure what else to put here. Should I change anything?
	end
end
1 Like

sorry for off-topic but… excuse me?

1 Like

Just edited it. Lol. My bad. :grimacing:

1 Like
local function CreateRay()
	local Camera = workspace:FindFirstChild("Camera")
	local Baseplate = workspace:FindFirstChild("Baseplate")
	if Camera and Baseplate then
		local RayParams = RaycastParams.new()
		RayParams.RespectCanCollide = true
		local Raycast = workspace:Raycast(Camera.Focus.Position, workspace.Baseplate.Position, RayParams.RespectCanCollide)
        if not Raycast then print("Nothing was hit...") return end
        print(Raycast.Instance.Name..":", Raycast.Instance:GetFullName())
	end
end
1 Like

It says “attempt to index nil with Instance.”

1 Like

I was re-editing it when you made that post lol

1 Like

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