Trying to switch the firemode on a gun system

So i decided to make an FPS game and ofcourse i needed a gun system, i found this one in the toolbox and decided to use it since i dont have that much free time. But the gun system is only automatic and i cant seem to figure out how to make it semi, if anyone has a solution please reply.

Main Handler :

Tool = script.Parent
maxammo = Tool.MaxAmmo
ammo = Tool.CurrentAmmo
ammo.Value = maxammo.Value
recoilpershot = Tool.RecoilPerShot.Value
recoilrecovery = Tool.RecoilRecovery.Value
currentrecoil = Tool.CurrentRecoil
local basespread = 50
maxrecoil = 350
handle = Tool.Handle
bayonet = Tool.Bayonet
light = handle.PointLight
firesound = handle.Fire
reloadsound = handle.Reload
meleesound = handle.MeleeSound
reloading = false
crouching = false
meleeing = false
meleecooldown = 0.5
canmelee = true
Debris = game:GetService("Debris")
storedhuman = nil
oghipheight = nil
colors = {45, 119, 21, 24, 23, 105, 104}
local idleanim = Tool:WaitForChild("Idle")
local loadedidle = nil
local shootanim = Tool:WaitForChild("Shoot")
local loadedshoot = nil
local reloadanim = Tool:WaitForChild("Reload")
local loadedreload = nil
local crouchanim = Tool:WaitForChild("Crouch")
local loadedcrouch = nil
local meleeanim = Tool:WaitForChild("MeleeA")
local loadedmelee = nil

function reload()
	if not reloading and not meleeing then
		if loadedreload==nil then
			local humanoid = Tool.Parent:FindFirstChild("Humanoid")
			loadedreload = humanoid:LoadAnimation(reloadanim)
			loadedreload.Priority = Enum.AnimationPriority.Action
		end
		local vCharacter = Tool.Parent
		local vPlayer = game.Players:playerFromCharacter(vCharacter)
		reloading=true
		Tool.Enabled=false
		ammo.Value=0
		script.Parent.reload:FireClient(vPlayer, 1)
		reloadsound:Play()
		loadedreload:Play()
		wait(3)
		ammo.Value=maxammo.Value
		Tool.Enabled=true
		reloading=false
		script.Parent.fire:FireClient(vPlayer, 1)
		script.Parent.reload:FireClient(vPlayer, 2)
	end
end

script.Parent:WaitForChild("melee").OnServerEvent:Connect(function(plr)
	local humanoid = Tool.Parent:FindFirstChild("Humanoid")
	if humanoid then
		storedhuman = humanoid
		melee()
	end

end)

function melee()
	if canmelee and not reloading then
		local vCharacter = Tool.Parent
		local vPlayer = game.Players:playerFromCharacter(vCharacter)
		local connection = handle.Touched:Connect(function(obj)
			if obj.Parent~=vCharacter then
				local victimhuman = obj.Parent:FindFirstChildWhichIsA("Humanoid")
				if victimhuman then
					victimhuman:TakeDamage(5)
				end
			end
		end)
		local connection2 = bayonet.Touched:Connect(function(obj)
			if obj.Parent~=vCharacter then
				local victimhuman = obj.Parent:FindFirstChildWhichIsA("Humanoid")
				if victimhuman then
					victimhuman:TakeDamage(0)
				end
			end
		end)
		meleesound:Play()
		--print("bash")
		canmelee=false
		meleeing=true
		currentrecoil.Value+=200
		if currentrecoil.Value>maxrecoil then
			currentrecoil.Value=maxrecoil
		end
		script.Parent.melee:FireClient(vPlayer, 1)
		loadedmelee:Play()
		wait(meleecooldown)
		connection:Disconnect()
		connection2:Disconnect()
		meleeing=false
		canmelee=true
	end
end

script.Parent:WaitForChild("crouch").OnServerEvent:Connect(function(plr)
	local humanoid = Tool.Parent:FindFirstChild("Humanoid")
	if humanoid then
		storedhuman = humanoid
		if oghipheight==nil then
			oghipheight = humanoid.HipHeight
		end
		if not crouching then
			crouching=true
			loadedidle:Stop()
			loadedcrouch:Play()
			humanoid.HipHeight=oghipheight-1.5
			local vCharacter = Tool.Parent
			local vPlayer = game.Players:playerFromCharacter(vCharacter)
			script.Parent.animate:FireClient(vPlayer,1)
		else
			crouching=false
			loadedidle:Play()
			loadedcrouch:Stop()
			humanoid.HipHeight=oghipheight
			local vCharacter = Tool.Parent
			local vPlayer = game.Players:playerFromCharacter(vCharacter)
			script.Parent.animate:FireClient(vPlayer,2)
		end
	end
end)

script.Parent:WaitForChild("animate").OnServerEvent:Connect(function(plr, animation)
	local humanoid = Tool.Parent:FindFirstChild("Humanoid")
	if humanoid then
		storedhuman = humanoid
		if oghipheight==nil then
			oghipheight = humanoid.HipHeight
		end
		if loadedidle==nil then
			loadedidle = humanoid:LoadAnimation(idleanim)
			loadedidle.Priority = Enum.AnimationPriority.Action
			loadedidle.Looped = true
		end
		if loadedshoot==nil then
			loadedshoot = humanoid:LoadAnimation(shootanim)
			loadedshoot.Priority = Enum.AnimationPriority.Action
		end
		if loadedcrouch==nil then
			loadedcrouch = humanoid:LoadAnimation(crouchanim)
			loadedcrouch.Priority = Enum.AnimationPriority.Action
			loadedcrouch.Looped = true
		end
		if loadedmelee==nil then
			loadedmelee = humanoid:LoadAnimation(meleeanim)
			loadedmelee.Priority = Enum.AnimationPriority.Action
		end
		if animation==1 then
			loadedidle:Play()
		end
		if animation==2 then
			loadedshoot:Play()
		end
		if animation==4 then
			loadedcrouch:Play()
		end
	end
	if animation==3 then
		loadedidle:Stop()
		loadedshoot:Stop()
		loadedcrouch:Stop()
		crouching=false
	end
end)

script.Parent:WaitForChild("reload").OnServerEvent:Connect(function(plr)
	if not reloading and ammo.Value<maxammo.Value and not meleeing then
		reload()
	end
end)

script.Parent:WaitForChild("fire").OnServerEvent:Connect(function(plr, v)
	if ammo.Value>0 and not reloading and not meleeing then
		ammo.Value-=1
		firesound:play()
		if loadedshoot then
			local MuzzlePoint = script.Parent.Handle.MuzzlePoint
			loadedshoot:Play()
			MuzzlePoint.Muzzle:Emit(100)
			MuzzlePoint.Smoke:Emit(4)
			MuzzlePoint.Sparks:Emit(20)
		end

		local vCharacter = Tool.Parent
		local vPlayer = game.Players:playerFromCharacter(vCharacter)
		script.Parent.reload:FireClient(vPlayer, 0)

		local missile = Instance.new("Part")

		local spawnPos = handle.Position

		local currecoil=currentrecoil.Value
		local actualspread=basespread+currecoil
		local spread = Vector3.new(math.random(-actualspread,actualspread)/10000,math.random(-actualspread,actualspread)/10000,math.random(-actualspread,actualspread)/10000)
		--print(actualspread)
		--print(currentrecoil.Value)
		currentrecoil.Value+=recoilpershot
		if currentrecoil.Value>maxrecoil then
			currentrecoil.Value=maxrecoil
		end

		spawnPos  = spawnPos + (v * 8)

		missile.Position = spawnPos
		--missile.Size = Vector3.new(1,1,1)
		missile.Velocity = (v+spread) * 300
		missile.CFrame = CFrame.new(missile.Position,missile.Position+missile.Velocity)
		--missile.BrickColor = BrickColor.new(colors[math.random(1, #colors)])
		missile.Size = Vector3.new(0.4,0.4,4)
		missile.BrickColor = BrickColor.new("Brick yellow")
		missile.Material = Enum.Material.Neon
		--missile.Shape = 0
		--missile.BottomSurface = 0
		--missile.TopSurface = 0
		missile.CanCollide=false
		missile.Name = "Bullet"
		missile.Elasticity = 0
		missile.Reflectance = 0
		missile.Friction = .9
		
		
		local force = Instance.new("BodyForce")
		force.force = Vector3.new(0,(workspace.Gravity*1) * missile:GetMass(),0) --0% gravity
		force.Parent = missile

		--local new = Tool.BrickCleanup:clone()
		--new.Parent = missile
		--new.Disabled = false

		local new_script = script.Parent.Paintball:clone()
		new_script.Disabled = false
		new_script.Parent = missile

		local creator_tag = Instance.new("ObjectValue")
		creator_tag.Value = vPlayer
		creator_tag.Name = "creator"
		creator_tag.Parent = missile

		missile.Parent = game.Workspace.ProjectileFolder

		if not light.Enabled then
			light.Enabled=true
			delay(0.1, function()
				if light.Enabled then
					light.Enabled=false
				end
			end)
		end

		--Debris:AddItem(missile,4)
		if ammo.Value<=0 then
			reload()
		end
	elseif not reloading and not meleeing then
		reload()
	end
end)

while true do
	wait(0.1)
	local currecoil=currentrecoil.Value
	if currecoil>0 then
		currentrecoil.Value-=recoilrecovery/10
		if currentrecoil.Value<=0 then
			currentrecoil.Value=0
		end
	end
end

Local Handler :

local MOUSE_ICON = 'rbxasset://textures/GunCursor.png'
local RELOADING_ICON = 'rbxasset://textures/GunWaitCursor.png'

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local toolammo = Tool:WaitForChild("CurrentAmmo")
local toolrecoil = Tool:WaitForChild("CurrentRecoil")
local firefunction = Tool.fire
local reloadfunction = Tool.reload
local animatefunction = Tool.animate
local crouchfunction = Tool.crouch
local meleefunction = Tool.melee
local storedhuman = nil
local idleanim = Tool.Idle
local loadedidle = nil
local shootanim = Tool.Shoot
local loadedshoot = nil
local crouchanim = Tool.Crouch
local loadedcrouch = nil
local meleeanim = Tool.MeleeA
local loadedmelee = nil
local zoomed = false

AmmoDisplay = script:WaitForChild("AmmoDisplay"):Clone()
AmmoDisplayClone = nil

local Mouse = nil

local function AdjustAmmoDisplay()
	local Frame = AmmoDisplayClone.Frame
	local Ammo = Frame.Ammo
	Ammo.AmmoCounter.CounterPart.Text = toolammo.Value
end

local function UpdateIcon()
	if Mouse then
		--Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
		--Mouse.Icon = MOUSE_ICON
		Mouse.Icon = toolammo.Value>0 and MOUSE_ICON or RELOADING_ICON
	end
end

local function OnEquipped(mouse)
	local Character = Tool.Parent
	local Player = Players:GetPlayerFromCharacter(Character)
	local PlayerGui = Player:FindFirstChild("PlayerGui")
	if PlayerGui then
		AmmoDisplayClone = AmmoDisplay:Clone()
		AdjustAmmoDisplay()
		AmmoDisplayClone.Parent = PlayerGui
	end
	local humanoid = Character:FindFirstChild("Humanoid")
	if humanoid then
		storedhuman = humanoid
	end
	if loadedidle==nil then
		loadedidle = humanoid:LoadAnimation(idleanim)
		loadedidle.Priority = Enum.AnimationPriority.Movement
		loadedidle.Looped = true
	end
	if loadedshoot==nil then
		loadedshoot = humanoid:LoadAnimation(shootanim)
		loadedshoot.Priority = Enum.AnimationPriority.Action
	end
	if loadedcrouch==nil then
		loadedcrouch = humanoid:LoadAnimation(crouchanim)
		loadedcrouch.Priority = Enum.AnimationPriority.Movement
		loadedcrouch.Looped = true
	end
	if loadedmelee==nil then
		loadedmelee = humanoid:LoadAnimation(meleeanim)
		loadedmelee.Priority = Enum.AnimationPriority.Action
	end
	loadedidle:Play()
	fanim(1)
	Mouse = mouse
	UserInputService.MouseIconEnabled=false
	UpdateIcon()
end

local function OnChanged(property)
	if property == 'Enabled' then
		UpdateIcon()
	end
end

function Unequipped()
	AmmoDisplayClone:Destroy()
	UserInputService.MouseIconEnabled=true
	loadedidle:Stop()
	loadedshoot:Stop()
	loadedcrouch:Stop()
	workspace.CurrentCamera.FieldOfView = 70
	zoomed = false
	fanim(3)
end

Tool.Equipped:connect(OnEquipped)
Tool.Changed:connect(OnChanged)
Tool.Unequipped:connect(Unequipped)

handle = Tool.Handle
mouse = game.Players.LocalPlayer:GetMouse()
local UserInputService = game:GetService("UserInputService")
local pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)

colors = {45, 119, 21, 24, 23, 105, 104}

function fire(v)
	firefunction:FireServer(v)
end

function reload()
	reloadfunction:FireServer()
end

function fanim(v)
	animatefunction:FireServer(v)
end

function crouch()
	--crouchfunction:FireServer()
end

function melee()
	meleefunction:FireServer()
end

local function checkhumanoid()
	local character = Tool.Parent;
	local humanoid = character:FindFirstChild("Humanoid")
	if humanoid then
		storedhuman = humanoid
		return true
	end
	if humanoid == nil then
		--print("Humanoid not found")
		return false
	elseif humanoid.Health<=0 then
		--print("u are ded not big surprise")
		return false
	end
end

local function onInputBegan(input, gameProcessed)
	if not checkhumanoid() then
		return
	end
	--if input.UserInputType == Enum.UserInputType.MouseButton2 then
	--	delay(0, function()
	--		while UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) do
	--			wait()
	--			workspace.CurrentCamera.FieldOfView = 30
	--		end
	--		workspace.CurrentCamera.FieldOfView = 70
	--	end)
	--end
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if UserInputService:IsKeyDown(Enum.KeyCode.R) then
			reload()
		end
		if UserInputService:IsKeyDown(Enum.KeyCode.C) then
			crouch()
		end
		if UserInputService:IsKeyDown(Enum.KeyCode.E) then
			if not zoomed then
				zoomed = true
				workspace.CurrentCamera.FieldOfView = 70
			else
				zoomed = false
				workspace.CurrentCamera.FieldOfView = 70
			end
		end
		if UserInputService:IsKeyDown(Enum.KeyCode.V) then
			melee()
		end
	end
end

script.Parent:WaitForChild("animate").OnClientEvent:Connect(function(id)
	if not checkhumanoid() then
		return
	end
	if id==1 then
		loadedidle:Stop()
		loadedcrouch:Play()
	end
	if id==2 then
		loadedidle:Play()
		loadedcrouch:Stop()
	end
end)

script.Parent:WaitForChild("melee").OnClientEvent:Connect(function(id)
	if not checkhumanoid() then
		return
	end
	if id==1 then
		loadedmelee:Play()
	end
end)

script.Parent:WaitForChild("reload").OnClientEvent:Connect(function(id)
	if not checkhumanoid() then
		return
	end
	AdjustAmmoDisplay()
	if id==1 then
		if AmmoDisplayClone and AmmoDisplayClone:FindFirstChild('Crosshair') then
			if AmmoDisplayClone.Crosshair:FindFirstChild('ReloadingLabel') then
				AmmoDisplayClone.Crosshair.ReloadingLabel.Visible = true
			end
		end
	end
	if id==2 then
		if AmmoDisplayClone and AmmoDisplayClone:FindFirstChild('Crosshair') then
			if AmmoDisplayClone.Crosshair:FindFirstChild('ReloadingLabel') then
				AmmoDisplayClone.Crosshair.ReloadingLabel.Visible = false
			end
		end
	end
end)

script.Parent:WaitForChild("fire").OnClientEvent:Connect(function(id)
	if not checkhumanoid() then
		return
	end
	if id==1 then
		UpdateIcon()
		AdjustAmmoDisplay()
	end
end)

Tool.Enabled = true
function onActivated()

	if not Tool.Enabled then
		return
	end
	pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
	while pressed do
		pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
		if pressed then
			Tool.Enabled = false

			local character = Tool.Parent;
			local humanoid = character:FindFirstChild("Humanoid")
			if humanoid then
				storedhuman = humanoid
			end
			if humanoid == nil then
				--print("Humanoid not found")
				return
			elseif humanoid.Health<=0 then
				--print("u are ded not big surprise")
				return
			end

			local targetPos = humanoid.TargetPoint
			local lookAt = (mouse.Hit.p - handle.Position).unit
			
			--fanim(2)
			fire(lookAt)
			
			wait(.123)

			Tool.Enabled = true
		end
	end
end

script.Parent.Activated:connect(onActivated)
UserInputService.InputBegan:Connect(onInputBegan)

while true do
	wait()
	if AmmoDisplayClone and AmmoDisplayClone:FindFirstChild('Crosshair') and Mouse then
		AmmoDisplayClone.Crosshair.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
		local absoluteY = 650
		AmmoDisplayClone.Crosshair:TweenSize(
			UDim2.new(0, toolrecoil.Value/10000 * absoluteY * 2 + 23, 0, toolrecoil.Value/10000 * absoluteY * 2 + 23),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Linear,
			0)
	end
end

--while true do
--	wait()
--	pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
--	if pressed==true then
--		if not Tool.Enabled then
--			return
--		end

--		Tool.Enabled = false

--		local character = Tool.Parent
--		local humanoid
--		if character then
--			humanoid = character.Humanoid
--		end
		
--		if humanoid then
--			local targetPos = humanoid.TargetPoint
--			local lookAt = (mouse.Hit.p - character.Head.Position).unit

--			fire(lookAt)

--			wait(.5)
--		end
--		Tool.Enabled = true
--	end
--	print(pressed)
--end

Credits to Rolleol for the gun scripts, just a reminder im using this only for a while till im free.

That is a very messy old code.
You can start by making a remote event (switch fire rate) and a numbervalue for the cooldown (semi?)
also a stringvalue to identify fire rate type.

-- FireRate is a string value to identify fire rate type
-- FireRateCoolDown is just cooldown but cooler!!!
--LOCAL 
game:GetService("UserInputService").InputBegan:Connect(function(Input, GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.P then -- Could be anything.
		SwitchFireRate:FireServer() 
	end
end)
--Main handler
local FireRates = {
	["Semi"] = function()
		FireRate.Value = "Auto"
		FireRateCoolDown.Value = 1
	end,
	["Auto"] = function()
		FireRate.Value = "Semi"
		FireRateCoolDown.Value = 0.1
	end,
}

SwitchFireRate.OnServerEvent:Connect(function()
	FireRates[FireRate.Value]()
end)
script.Parent:WaitForChild("fire").OnServerEvent:Connect(function(plr, v)
	if ammo.Value>0 and not reloading and not meleeing then
		if not game:GetService("CollectionService"):HasTag(plr, "OnCooldown") then
			game:GetService("CollectionService"):AddTag(plr, "OnCooldown")
			task.delay(FireRateCooldown.Value, function()
				game:GetService("CollectionService"):RemoveTag(plr, "OnCooldown")
			end)
			ammo.Value-=1
			firesound:play()
			if loadedshoot then
				local MuzzlePoint = script.Parent.Handle.MuzzlePoint
				loadedshoot:Play()
				MuzzlePoint.Muzzle:Emit(100)
				MuzzlePoint.Smoke:Emit(4)
				MuzzlePoint.Sparks:Emit(20)
			end

			local vCharacter = Tool.Parent
			local vPlayer = game.Players:playerFromCharacter(vCharacter)
			script.Parent.reload:FireClient(vPlayer, 0)

			local missile = Instance.new("Part")

			local spawnPos = handle.Position

			local currecoil=currentrecoil.Value
			local actualspread=basespread+currecoil
			local spread = Vector3.new(math.random(-actualspread,actualspread)/10000,math.random(-actualspread,actualspread)/10000,math.random(-actualspread,actualspread)/10000)
			--print(actualspread)
			--print(currentrecoil.Value)
			currentrecoil.Value+=recoilpershot
			if currentrecoil.Value>maxrecoil then
				currentrecoil.Value=maxrecoil
			end

			spawnPos  = spawnPos + (v * 8)

			missile.Position = spawnPos
			--missile.Size = Vector3.new(1,1,1)
			missile.Velocity = (v+spread) * 300
			missile.CFrame = CFrame.new(missile.Position,missile.Position+missile.Velocity)
			--missile.BrickColor = BrickColor.new(colors[math.random(1, #colors)])
			missile.Size = Vector3.new(0.4,0.4,4)
			missile.BrickColor = BrickColor.new("Brick yellow")
			missile.Material = Enum.Material.Neon
			--missile.Shape = 0
			--missile.BottomSurface = 0
			--missile.TopSurface = 0
			missile.CanCollide=false
			missile.Name = "Bullet"
			missile.Elasticity = 0
			missile.Reflectance = 0
			missile.Friction = .9


			local force = Instance.new("BodyForce")
			force.force = Vector3.new(0,(workspace.Gravity*1) * missile:GetMass(),0) --0% gravity
			force.Parent = missile

			--local new = Tool.BrickCleanup:clone()
			--new.Parent = missile
			--new.Disabled = false

			local new_script = script.Parent.Paintball:clone()
			new_script.Disabled = false
			new_script.Parent = missile

			local creator_tag = Instance.new("ObjectValue")
			creator_tag.Value = vPlayer
			creator_tag.Name = "creator"
			creator_tag.Parent = missile

			missile.Parent = game.Workspace.ProjectileFolder

			if not light.Enabled then
				light.Enabled=true
				delay(0.1, function()
					if light.Enabled then
						light.Enabled=false
					end
				end)
			end
		end

		--Debris:AddItem(missile,4)
		if ammo.Value<=0 then
			reload()
		end
	elseif not reloading and not meleeing then
		reload()
	end
end)

If you want this to be mobile-friendly, just make a button that listens for a remote in player character.

Well i was thinking of making the gun Semi, not automatic. Any ideas for that ?

That’s what it does, it switches from auto to semi and vice versa