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

RayCast doesnt work when shooting towards sky?

I have made a gun, but I have a problem using it when clicking with my mouse icon on the sky. I've browsed around the internet, looked around on wiki and I know it has something to do with my mouse and I've seen people talking about mouse.Hit.p or mouse.Target but I'm using UserInputService. Does anybody know what I could of done differently that would allow me to shoot in the sky?

Here is a clip of the code I'm using for the raycast.

		local RayCast = Ray.new(FP, (TP-FP).unit*100)
	local Part, Position, Normal = game.Workspace:FindPartOnRay(RayCast, 							Player.Character, false, true)
	if Part then 
		local Hum = Part.Parent:FindFirstChild("Humanoid")
		if Hum then
			Hum:TakeDamage(100)
		end
	
	
		
		local Bullet = game.ReplicatedStorage.Bullet:Clone()
		Bullet.Parent = workspace
		local Dist = (TP-FP).magnitude
		Bullet.CFrame = CFrame.new(FP, Position)*CFrame.new(0,0, Dist/-37)
		local Dist = (TP-FP).magnitude
		
		local force = Instance.new("BodyThrust")
		force.Force = Vector3.new(0, 0, -40)
		force.Parent = Bullet
		Bullet.Anchored = false
		Bullet.Transparency = 0
		
		wait(0.1)
		force:Destroy()
		wait(0.6)
		Bullet:Destroy()
		

1 answer

✓ Accepted answer

FindPartOnRay only returns a Part when it hits something, because there are no parts in the sky, your if Part then will never pass.

2 comments

0

I've tried putting a part way up in the sky, so it has a part to return. It still won't shoot however. Also I've noticed shooting in far ranges is a little buggy too, is there any ideal way to create a MaxDistance of the sorts?

0

You already have one: unit*100

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