the issue is likely due to how the bullet direction is calculated in relation to the camera when zoomed out. since you’re using viewportpointtoray to calculate the bullet’s direction, it’s possible that the bullet is aiming toward the cameras position rather than a proper point in the world. this can happen when the mouse is far from the center of the screen especially when zooming out.
to fix this, you can adjust the direction of the bullet by ensuring it’s always fired in the direction from the muzzle not directly toward the camera. you could try using a more consistent method of raycasting or make sure the mouse input is correctly adjusted.
if it helps, this is the old code I used, This one worked normally
local bulletSpreadRandomizer = Random.new(Workspace:GetServerTimeNow() * 100000)
local travelDistance = tool:GetAttribute("TravelDistance")
local mouseLocation = UserInputService:GetMouseLocation()
local viewportPointToRay = currentCamera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
local muzzlePosition = muzzle.WorldPosition
local viewportRayDirection = viewportPointToRay.Direction * travelDistance
local viewportRaycast = Workspace:Raycast(viewportPointToRay.Origin, viewportRayDirection, raycastParameters)
local viewportIntersection = viewportRaycast and viewportRaycast.Position or viewportPointToRay.Origin + viewportRayDirection
local bulletRay = Ray.new(muzzlePosition, (viewportIntersection - muzzlePosition).Unit * travelDistance)
local bulletRaycast = Workspace:Raycast(bulletRay.Origin, bulletRay.Direction, raycastParameters)
local bulletIntersection = bulletRaycast and bulletRaycast.Position or viewportIntersection
local bulletLength = (muzzlePosition - bulletIntersection).Magnitude
local bulletResultInstance = bulletRaycast and bulletRaycast.Instance
so it seems found the problem you are facing the problem is that Roblox has a limit and if you zoom too far out it cant find your character or you didn’t create a viewportraycase.So both are fixable if you didn’t create a viewportraycase just create it and if you go so far that Roblox cant find your character that you need to add a fallback.I seemed like an artificial inteligence because i saw other people speak respectfully with a good vocabulary and i wanted to be straight and helpful.i haven.t finished the code it will be ready in a bit.
a good fix could be to add to the bottom
if mouseLocation = nil then
Part.Position = BulletRaycast
end
so it dosent glitch out but iam going to test it myself to be shure