Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my shotgun's bullets only shooting when I aim at the ground and not at the sky?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago

I'm making a shotgun, and when I shoot, the bullets raycast only appears when I shoot it at the ground, and not the sky. Help!

function Fire()
    for i = 10,0,-1 do
        local ray =  Ray.new(Tool.Handle.CFrame.p, (Mouse.Hit.p - Tool.Handle.CFrame.p + Vector3.new(math.random(-2,2), math.random(-2,2), 0)) * 1000)
        local part, position = workspace:FindPartOnRay(ray, Player.Character, false, true)
        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Electric blue")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.5
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false
        local distance = (Tool.Handle.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(Tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
        game:GetService("Debris"):AddItem(beam, 0.1)
        Tool.Fire:Play()
        if part then
            local humanoid = part.Parent:FindFirstChild("Humanoid") 

            if not humanoid then
                humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
            end

        if humanoid then
            humanoid:TakeDamage(10)
            if humanoid.Health == 0 then
                Player.leaderstats.Eliminations.Value = Player.leaderstats.Eliminations.Value + 1
                KilledPerson.Value = humanoid.Parent.Name
                Player.PlayerGui.KillCounter.TextLabel.Text = "You killed "..KilledPerson.Value.."!"
                wait(3)
                Player.PlayerGui.KillCounter.TextLabel.Text = ""
            end 
        end
    end
    end
end
0
FormFactor is deprecated, why are you using it. Same for the parent argument to Instance.new. User#19524 175 — 5y
0
This is most likely happening because the ray isn't actually hitting anything when it's aiming at the sky. If you really want your shots to show up when they don't hit anything, just add in the following after setting your position the first time: position = position or Vector3.new(-- some random spray position); Then it'll seem like it's firing at something when it's actually not. saenae 318 — 5y

Answer this question