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

How can I make a raycast to a nil point?

It's a confusing question, I know, but I've tried to deal in raycasting (something Kenetic should add as a tag), and I've found that you can only fire at an existing brick and not the skybox, or else the script breaks. How do I do a workaround? I've tried just replacing the mouse.Hit.p with 999, but it was as if I had done nothing to it. It still broke after I shot at the skybox.

Here's my code:

function drawTrail (mag,position,ry)
	local trail = Instance.new ('Part', Workspace);
	trail.formFactor = Enum.FormFactor.Custom
	if mouse.Hit.p ~= nil then 
	trail.Size =  Vector3.new(0.1, 0.1, mag)
	trail.CFrame = CFrame.new ((script.Parent.Handle.CFrame.p + mouse.Hit.p)/2, mouse.Hit.p)
	else trail.Size = Vector3.new (.1,.1,999)
		trail.CFrame = CFrame.new ((script.Parent.Handle.CFrame.p + Vector3.new (999,999,999))/2, Vector3.new (999,999,999))
	end
	trail.BrickColor = BrickColor.new ('Mid grey')
	trail.Transparency = .5	
	trail.Anchored = true
    trail.CanCollide = false
    trail.TopSurface = Enum.SurfaceType.Smooth
    trail.BottomSurface = Enum.SurfaceType.Smooth
    for i = .5,1,.1 do
		trail.Transparency = i
		wait (.1)
	end
	game.Debris:AddItem (trail, .1)
end

2 answers

I never knew that it would break if you shot at a skybox... Hm. Well, as you said "you can only fire at an existing brick". So why not just add a lining on the inside of the skybox as a loophole?

1 comment

0

I was thinking of that, but hoping for a better solution. I know those bigshot clans never do that, so there must be a way! Thanks for the help, though. Appreciate it!

The best fix is if the raycast function doesn't return a part, that it uses the Mouse's Hit and shoot at that instead, but limited to a maximum size to reduce lag.

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