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

A problem with shell ejecting script in my guns?

Asked by
pecax 0
2 years ago

So basically I got a gun system and i got a script that makes it drop bullet shells but the problem is it drops the shells when the gun is empty. Heres the script:

local tool = script.Parent

local shell = game.ReplicatedStorage:WaitForChild("PistolShell")

tool.Activated:Connect(function()

local shellClone = shell:Clone()
shellClone.CanCollide = true

shellClone.Parent = workspace
wait()
local shellPos = script.Parent.Bolt.Position
shellClone.Position = Vector3.new(shellPos.X, shellPos.Y, shellPos.Z)

wait(2)

shellClone.CanCollide = false

end)

Thanks

0
Ofc it will keep going even if it is 'empty'. You didn't put a if statement to check if it is empty. AProgrammR 398 — 2y

1 answer

Log in to vote
0
Answered by
itsbboy 17
2 years ago

I had the same problem but for a Garand ping sound, but I do not know if you use a value for your ammo counter. Either way, it should work.

tool.Activated:Connect(function()
    if (YourAmmoCounter).Value >= 1 then
        local shellClone = shell:Clone()
        shellClone.CanCollide = true

        shellClone.Parent = workspace
        wait()
        local shellPos = script.Parent.Bolt.Position
        shellClone.Position = Vector3.new(shellPos.X, shellPos.Y, shellPos.Z)

        wait(2)

        shellClone.CanCollide = false
    end
end)
Ad

Answer this question