Anyways, this is an ammo box script, designed mostly for TurboFusion's gun scripts. Anyways, what I need this script to do, is to figure out the name of the tool instead of the classname, so if the gun's named "Double Shotgun" or "Auto Shotgun" the script will only give ammo to those two gun types. Also, there's a glitch where you have 199 ammo, it'll give you 219, which I have no idea how to fix. If someone could help me with the bug, and making it so it'll read the name of the tool, and not the classname, that'd be EXTREMELY helpful!!
Here's the code:
function onTouched(hit) if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then local d = hit.Parent:GetChildren() for i=1, #d do if (d[i].className == "Tool") then if d[i].Ammo.Value == 200 then --This is the max ammo for the gun. return nil else d[i].Ammo.Value = d[i].Ammo.Value +20 script.Sound:play() script.Parent.AmmoLeft.Value = script.Parent.AmmoLeft.Value -0 script.Disabled = true script.Parent.Transparency = 1 wait(10) script.Disabled = false script.Parent.Transparency = 0 end end end end end script.Parent.Touched:connect(onTouched)
To remove the glitch, add a "Less Than or Equal To" operator (<=) instead of an "Equal To" operator (==) on line 6. For making it check the name, you can add an or statement on line 5.
function onTouched(hit) if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then local d = hit.Parent:GetChildren() for i=1, #d do if d[i].Name == "Double Shotgun" or d[i].Name == "Auto Shotgun" then if d[i].Ammo.Value <= 200 then --This is the max ammo for the gun. return nil else d[i].Ammo.Value = d[i].Ammo.Value +20 script.Sound:play() script.Parent.AmmoLeft.Value = script.Parent.AmmoLeft.Value -0 script.Disabled = true script.Parent.Transparency = 1 wait(10) script.Disabled = false script.Parent.Transparency = 0 end end end end end script.Parent.Touched:connect(onTouched)