Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

A problem with shell ejecting script in my guns?

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

1 comment

0

Ofc it will keep going even if it is 'empty'. You didn't put a if statement to check if it is empty.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.