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

How do I make this gun script not reload when its full ammo?

This is where the script is in: Tool > LocalScript, but there is a handle in the tool so here is the script:

Player = game.Players.LocalPlayer
Gun = script.Parent
Ammo = 10
MaxAmmo = 10
Max = 50
mouse = Player:GetMouse()
BulletDamage = 10
enabled = true

function Shoot()
	if Ammo >= 1 and enabled == true then
		enabled = false
		IsFiring = true
		Firing()
	end
end

function Firing()
	repeat wait(0.2)
		
		function Damage(Part)
			if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent.Name == "Zombie" then
				Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -BulletDamage
				Bullet:Destroy()
			end
		end
		Ammo = Ammo -1
		print("You have "..Ammo.." ammo left!!")
		enabled = false
		Bullet = Instance.new("Part", Workspace)
		Gun.GripPos = Vector3.new(0,0.3,0)
		game.Debris:AddItem(Bullet,2)
		Bullet.Shape = "Ball"
		Bullet.Size = Vector3.new(0.1,0.1,0.1)
		Bullet.TopSurface = "Smooth"
		Bullet.BottomSurface = "Smooth"
		Bullet.BrickColor = BrickColor.new("Really black")
		Bullet.CanCollide = false
		Bullet.CFrame = Gun.Handle.CFrame
		Bullet.CFrame = CFrame.new(Bullet.Position,mouse.Hit.p)
		BM = Instance.new("SpecialMesh",Bullet)
		BM.MeshType = "Sphere"
		BM.Scale = Vector3.new(0.2,0.2,0.2)
		v = Instance.new("BodyVelocity", Bullet)
		v.velocity = Bullet.CFrame.lookVector *90
		v.maxForce = Vector3.new(math.huge,math.huge,math.huge)
		Fire = Instance.new("Sound", Bullet)
		Fire.SoundId = "http://www.roblox.com/asset/?id=131419157"
		RP = math.random(10,20)
		RP = RP/10
		Fire.Pitch = RP
		RV = math.random(70,90)
		RV = RV/10
		Fire.Volume = RV
		Fire:Play()
		game.Debris:AddItem(Fire, 2)
		Bullet.Touched:connect(Damage)
		wait()
		Gun.GripPos = Vector3.new(0,0,0)
		enabled = true
		
	until IsFiring == false or Ammo == 0
end
function StopShooting()
	IsFiring = false
end

function Reload(key)
	key = key:lower()
	if enabled == true and Ammo < 20 and key == "r"  then
		enabled = false
		if Ammo == 0 then
			Max = Max -10
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 1 then
			Max = Max -1
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 2 then
			Max = Max -2
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 3 then
			Max = Max -3
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 4 then
			Max = Max -4
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 5 then
			Max = Max -5
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 6 then
			Max = Max -6
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 7 then
			Max = Max -7
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 9 then
			Max = Max -9
			print("You have "..Max.." maxammo left!!")
		end
		if Ammo == 10 then
			--????????? What do i do here? test this once
			
			end
		RS = Player.Character.Torso["Right Shoulder"]
		for i = 1,4 do
			RS.C0 = RS.C0 *CFrame.Angles(0,0,0.2)
			wait()
		end
		
		repeat wait(0.1)
			Ammo = Ammo +1
			RS.C0 = RS.C0 *CFrame.Angles(0.2,0,0)
			Shell = Instance.new("Part",Workspace)
			Shell.TopSurface = "Smooth"
			Shell.BottomSurface = "Smooth"
			Shell.Reflectance = 0.2
			Shell.BrickColor =BrickColor.new "Black"
			Shell.CanCollide = false
			Shell.Size = Vector3.new(1, 1, 1)
			ShellMesh = Instance.new("BlockMesh",Shell)
			ShellMesh.Scale = Vector3.new(0.2,0.3,0.45)
			game.Debris:AddItem(Shell,0.8)
			Shell.CFrame = Gun.Handle.CFrame *CFrame.new(0,-0.5,-0.3)
			wait(0.1)
			RS.C0 = RS.C0 *CFrame.Angles(-0.2,0,0)		
		until Ammo == MaxAmmo
		for i = 1,4 do
			RS.C0 = RS.C0 *CFrame.Angles(0,0,-0.2)
			wait()
		end
		wait()
		enabled = true
		end
	end
mouse.KeyDown:connect(Reload)
Gun.Deactivated:connect(StopShooting)
Gun.Activated:connect(Shoot)

Please help me and try it out for your self if you can figger it out. Thanks.

1 answer

✓ Accepted answer

Player = game.Players.LocalPlayer Gun = script.Parent Ammo = 10 MaxAmmo = 10 Max = 50 mouse = Player:GetMouse() BulletDamage = 10 enabled = true

function Shoot() if Ammo >= 1 and enabled == true then enabled = false IsFiring = true Firing() end end

function Firing() repeat wait(0.2)

    function Damage(Part)
        if Part.Parent:FindFirstChild("Humanoid") ~= nil and Part.Parent.Name == "Zombie" then
            Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health -BulletDamage
            Bullet:Destroy()
        end
    end
    Ammo = Ammo -1
    print("You have "..Ammo.." ammo left!!")
    enabled = false
    Bullet = Instance.new("Part", Workspace)
    Gun.GripPos = Vector3.new(0,0.3,0)
    game.Debris:AddItem(Bullet,2)
    Bullet.Shape = "Ball"
    Bullet.Size = Vector3.new(0.1,0.1,0.1)
    Bullet.TopSurface = "Smooth"
    Bullet.BottomSurface = "Smooth"
    Bullet.BrickColor = BrickColor.new("Really black")
    Bullet.CanCollide = false
    Bullet.CFrame = Gun.Handle.CFrame
    Bullet.CFrame = CFrame.new(Bullet.Position,mouse.Hit.p)
    BM = Instance.new("SpecialMesh",Bullet)
    BM.MeshType = "Sphere"
    BM.Scale = Vector3.new(0.2,0.2,0.2)
    v = Instance.new("BodyVelocity", Bullet)
    v.velocity = Bullet.CFrame.lookVector *90
    v.maxForce = Vector3.new(math.huge,math.huge,math.huge)
    Fire = Instance.new("Sound", Bullet)
    Fire.SoundId = "http://www.roblox.com/asset/?id=131419157"
    RP = math.random(10,20)
    RP = RP/10
    Fire.Pitch = RP
    RV = math.random(70,90)
    RV = RV/10
    Fire.Volume = RV
    Fire:Play()
    game.Debris:AddItem(Fire, 2)
    Bullet.Touched:connect(Damage)
    wait()
    Gun.GripPos = Vector3.new(0,0,0)
    enabled = true

until IsFiring == false or Ammo == 0

end function StopShooting() IsFiring = false end

function Reload(key) key = key:lower() if enabled == true and Ammo < 20 and key == "r" then enabled = false if Ammo == 0 then Max = Max -10 print("You have "..Max.." maxammo left!!") end if Ammo == 1 then Max = Max -1 print("You have "..Max.." maxammo left!!") end if Ammo == 2 then Max = Max -2 print("You have "..Max.." maxammo left!!") end if Ammo == 3 then Max = Max -3 print("You have "..Max.." maxammo left!!") end if Ammo == 4 then Max = Max -4 print("You have "..Max.." maxammo left!!") end if Ammo == 5 then Max = Max -5 print("You have "..Max.." maxammo left!!") end if Ammo == 6 then Max = Max -6 print("You have "..Max.." maxammo left!!") end if Ammo == 7 then Max = Max -7 print("You have "..Max.." maxammo left!!") end if Ammo == 9 then Max = Max -9 print("You have "..Max.." maxammo left!!") end if Ammo == 10 then print("Full.") end RS = Player.Character.Torso["Right Shoulder"] for i = 1,4 do RS.C0 = RS.C0 *CFrame.Angles(0,0,0.2) wait() end

    repeat wait(0.1)
        Ammo = Ammo +1
        RS.C0 = RS.C0 *CFrame.Angles(0.2,0,0)
        Shell = Instance.new("Part",Workspace)
        Shell.TopSurface = "Smooth"
        Shell.BottomSurface = "Smooth"
        Shell.Reflectance = 0.2
        Shell.BrickColor =BrickColor.new "Black"
        Shell.CanCollide = false
        Shell.Size = Vector3.new(1, 1, 1)
        ShellMesh = Instance.new("BlockMesh",Shell)
        ShellMesh.Scale = Vector3.new(0.2,0.3,0.45)
        game.Debris:AddItem(Shell,0.8)
        Shell.CFrame = Gun.Handle.CFrame *CFrame.new(0,-0.5,-0.3)
        wait(0.1)
        RS.C0 = RS.C0 *CFrame.Angles(-0.2,0,0)      
    until Ammo == MaxAmmo
    for i = 1,4 do
        RS.C0 = RS.C0 *CFrame.Angles(0,0,-0.2)
        wait()
    end
    wait()
    enabled = true
    end
end

mouse.KeyDown:connect(Reload) Gun.Deactivated:connect(StopShooting) Gun.Activated:connect(Shoot)

1 comment

0

thank you so much but can you plz fix the code block

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