I have a gun which has a script in it that detects if the NumberValue named Ammo reaches 0, once it does reach zero it should stop the tool from functioning and parent the tool to ServerStorage. However, for some reason it doesn’t work. No errors, and as far as I know the script stops working when it gets to detecting when the value reaches zero. I’m stuck on what to do and any help would be appreciated
local Tool = script.Parent
local Ammo = Tool.Ammo
local MaxAmmo = Tool.MaxAmmo
local WeaponStorage = game.ServerStorage.Weapons
Tool.Activated:Connect(function()
if Ammo.Value <= 0 then
Tool.Sounds.OutOfAmmo:Play()
Tool.Enabled = false
task.wait(0.5)
Tool.Parent = WeaponStorage
end
end)
local Tool = script.Parent
local Ammo = Tool:WaitForChild("Ammo")
local WeaponStorage = game.ServerStorage.Weapons
local SoundsFolder = Tool:WaitForChild("Sounds")
local OutOfAmmoSound = SoundsFolder:WaitForChild("OutOfAmmo")
local function checkAmmo()
if Ammo.Value <= 0 then
OutOfAmmoSound:Play()
Tool.Enabled = false
task.wait(0.5)
Tool.Parent = WeaponStorage
end
end
Ammo:GetPropertyChangedSignal("Value"):Connect(checkAmmo)
Tool.Activated:Connect(checkAmmo)
There are many ways to do this. You have a few examples. Maybe something else isn’t set up correctly. I’m not testing here; I have nothing to work with, so it’s all really speculation.
show me more of the script and I will adjust it fully show me the part where the tool is “functioning” like shooting a bullet or damaging for ex i can clean it up too