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

how do i set my distance on my ray casting gun?

heres my script


game.Players.PlayerAdded:Connect(function(p)
	mouse = p:GetMouse()
	distance = 15
	mouse.Button1Down:Connect(function()
		ray = Ray.new(mouse.hit.p,(mouse.hit.p - p.Character.UpperTorso.CFrame.p).unit * 2)
		hit,pos = workspace:FindPartOnRay(ray,p.Character,false,true)
		
		line = Instance.new("Part",workspace)
		line.BrickColor = BrickColor.new("Really red")
		line.Anchored = true
		line.CanCollide = false
		line.Transparency = 0.3
		line.Name = "Line"
		local dir = (p.Character.UpperTorso.CFrame.p - pos).Magnitude
		line.Size = Vector3.new(0.3,0.3,dir)
		line.CFrame = CFrame.new(p.Character.UpperTorso.CFrame.p,pos) * CFrame.new(0,0,-dir/2)
		print("done")
	end)
	
end)

i really dont know what im doing wrong lol

ps: the part where it says like .unit * 2 doesent work i use to but not any more

1 answer

The issue is in line 5. The ray starts at the hit position instead of whatever it's supposed to come out of.

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