Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

raycast not finding a part?

so i have a local script which fires a remote function inside of itself to check if theres a part infront of the player or not, the remote event IS fired but it always prints "not found" even while i stand infront of a wall

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,command)
	local char = plr.Character
	
	if command == "Check" then
		local ray = Ray.new(char.HumanoidRootPart.Position, Vector3.new(0,0,-1.5))
		local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray,char:GetChildren(),false,true)
		
		if hit then
			print(hit.Name)
			local bruh = Instance.new("Part",workspace)
			bruh.Name = "Bruh"
			bruh.Anchored = true
			bruh.CFrame = CFrame.new(position)
		elseif not hit then
			print("not found")
		end
	end
end)

anybody knows what im doing wrong??

3 comments

0

Your ignore list, it's ignoring the character?

0

i'm pretty sure it is but i'm gonna try to change it to just findpartonray

0

changing it to game.Workspace:FindPartOnRay(ray,char,false,true) has the same issue

1 answer

so i gave up on trying that and instead i went with a different approach

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr,command)
	local char = plr.Character
	
	if command == "Check" then
		local offset = Vector3.new(0,0,-1.5)
		local ray = Ray.new(char.HumanoidRootPart.Position,(char.HumanoidRootPart.CFrame*CFrame.new(offset).lookVector))
		local hit, position = game.Workspace:FindPartOnRay(ray,char,false,true)
		
		if (char.HumanoidRootPart.Position - position).magnitude < 3 then
			print("close enough")
		elseif (char.HumanoidRootPart.Position - position).magnitude > 3 then
			print("too far")
		end
	end
end)

this one here seems to work "perfectly". i haven't tried anything complicated with it yet but i think i can use it for what im trying to do

This discussion is preserved as it was. New answers, comments, and votes are closed.