Bullets don’t appear when aiming at the sky because the ray hits nothing, so it’ll be nil. What I would do is to detect if there is a raycastResult and if it’s nil then simply just set the bullets to go to the direction, from the origin.
(Following your code, add an else statement and then set the bullet CFrame to the range, from the barrelPosition)
if raycastResult then
else
bullet.CFrame = CFrame.new(barrelPosition,(mousePosition - barrelPosition).unit * RANGE)
-- basically origin + direction
end
This makes so much sense and thank you for the concise explanation but I still end up a with a little bit of a problem. When I shoot the sky, the bullets appear but they do not position from the origin to the mouse position. This problem also happens when my mouse goes past the gun’s range that I have set.
I’m not really sure what would cause it, you might need to debug it yourself or ask someone else or you can send file or code to me because somehow I am better at helping whenever I fix it myself by place file or script since I don’t know some CFrame expectations.
Anyway, I believe it’s a cframe problem or raycast. Also what is * CFrame.new(0,0,-distance/2)?