Raycast Weapon problem

I have created a Raycast gun system that takes the mouse hit position and casts a ray to that position. The only problem is that you cannot shoot into the air with this weapon, so the only thing it allows you to shoot at is physical parts in the workplace. Could someone help me on what should be done to achieve this goal?

– Tool Fires server when it detects the tool is activated

RemoteStorage.fireEvent:FireServer(Weapon.MuzzlePoint.CFrame.p, Mouse.Hit.p, Weapon)

– Raycasting in a server script

Remote.OnServerEvent:Connect(function(player, muzzlePos, mousePos, Weapon) local ray = Ray.new(muzzlePos, (mousePos - muzzlePos).unit * 400) local Part, Position = game.Workspace:FindPartOnRay(ray, player.Character, false, true) local Distance = (muzzlePos - mousePos).magnitude Remote:FireAllClients(player, Part, Position, Distance, muzzlePos) end)

– It then creates the ray bullet

bulletPart.Size = Vector3.new(0.5,0.5,Distance) bulletPart.CFrame = CFrame.new(muzzlePos, Position) * CFrame.new(0,0, -Distance/2)

– gif
https://gyazo.com/75159accb502503d2bec4d7a8f25b08a

I know that it has something to do with changing the ‘mouse.hit.p’, but I am unsure to what I would do instead of this.

I think replacing that part to local Distance = (muzzlePos - Position).magnitude may be able to solve this problem.

2 Likes

Thank you for the simple solve.

Not a problem, I’m glad I could’ve helped you. :slight_smile: