Help with workspace:Raycast()

I created a raycasting script with workspace:Raycast() but for some reason it only hits the workspace baseplate and not the parts in front.

This script only does the raycast once, putting it in a loop should resolve the issue.

Also recommend not screen shotting and formatting your code using ```. This is because you will need to update certain variables in the loop.

I tried putting it in a loop and it didn’t work.

Put your code in ``` format please, I do not have the time to retype the code from the picture in order to make corrections.

local cam = workspace.CurrentCamera

local camPos = cam.CFrame.Position

local raycastParams = RaycastParams.new()

raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

raycastParams.FilterDescendantsInstances = {char}

raycastParams.IgnoreWater = true

local maxDistance = 30

local ray = workspace:Raycast(camPos, cam.CFrame.LookVectormaxDistance, raycastParams)*

print(ray.Instance:GetFullName())

Thank you for providing the code here are the edits:

--Script goes under starter character scripts to get the character properly
local cam = workspace.CurrentCamera

local char = script.Parent

local raycastParams = RaycastParams.new()

raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

raycastParams.FilterDescendantsInstances = {char}

raycastParams.IgnoreWater = true

local maxDistance = 30

while true do
	local camPos = cam.CFrame.Position

	local ray = workspace:Raycast(camPos, cam.CFrame.LookVector*maxDistance, raycastParams)
	if ray then
		print(ray.Instance:GetFullName())
	end
	task.wait(1)
end

This should work from what I have tested

2 Likes

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