Changing Modes For My Guns

So Today Im Making a DarkRP Based Game And I Decided To Use My Other Weapon Engine That Im Not Even Working On Anymore, But I Want To Ask,
How Do I Make My Gun Semi And Recoil System That Works On Auto And Semi ?
The Codes Is Listed Below
Handler :

local character
local humanoid
local animator
local animate
local animate2
local equipped = false
local filterArray = {}
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

damage = 8

script.Parent.RequestFire.OnServerEvent:Connect(function(plr,targetPosition)
	if script.Parent:FindFirstChild("Handle") and equipped == true then
		if animate2 then
			animate2:Stop()
		end
		animate2 = animator:LoadAnimation(script.Fire)
		animate2:Play()
		
		local spreadPosition = targetPosition + Vector3.new(math.random(-500,500)/1250,math.random(-500,500)/1250,math.random(-500,500)/1250)
		
		local raycastResult = workspace:Raycast(
			(script.Parent.Handle.CFrame * CFrame.new(-1.9,0.11,0)).Position,
			(spreadPosition - (script.Parent.Handle.CFrame * CFrame.new(-1.9,0.11,0)).Position).Unit*500,
			raycastParams)

		if raycastResult then
			local partHit = raycastResult.Instance
			if partHit.Parent:FindFirstChild("Humanoid") then
				if partHit.Parent.Humanoid.Health > 0 then
					if partHit.Name == "Head" then
						partHit.Parent.Humanoid:TakeDamage(damage*2.5)
					else
						partHit.Parent.Humanoid:TakeDamage(damage)
					end
					if partHit.Parent:FindFirstChild("Burn") == nil then
						local burn = script.Burn:Clone()
						burn.Parent = partHit.Parent
						burn.Disabled = false
					else
						partHit.Parent:FindFirstChild("Burn").BurningTime.Value = partHit.Parent:FindFirstChild("Burn").BurningTime.Value + 2
					end
				end
			elseif partHit.Parent:IsA("Accessory") then
				for _, ins in pairs(partHit.Parent.Parent:GetChildren()) do
					if ins:IsA("Accessory") then
						table.insert(filterArray,ins)
					end
				end
				raycastParams.FilterDescendantsInstances = filterArray
			end
		end
		coroutine.wrap(function()
			script.Parent.Handle.PointLight.Enabled = true
			script.Parent.Handle.BillboardGui.Enabled = true
			script.Parent.Rpart.MuzzleEffect.Enabled = true
			script.Parent.Chamber.ShellEffect.Enabled = true
			script.Parent.Bolt.Transparency = 1
			script.Parent.BoltBack.Transparency = 0
			wait(.08)
			script.Parent.Handle.PointLight.Enabled = false
			script.Parent.Handle.BillboardGui.Enabled = false
			script.Parent.Rpart.MuzzleEffect.Enabled = false
			script.Parent.Chamber.ShellEffect.Enabled = false
			script.Parent.Bolt.Transparency = 0
			script.Parent.BoltBack.Transparency = 1
		end)()
		local trailPart = Instance.new("Part",workspace)
		trailPart.Name = "TrailPart"
		trailPart.Transparency = 1
		trailPart.CanCollide = false
		trailPart.Anchored = true
		local attachment1 = Instance.new("Attachment",trailPart)
		local beam = Instance.new("Beam",trailPart)
		game.Debris:AddItem(attachment1,.075)
		game.Debris:AddItem(trailPart,.075)
		attachment1.WorldPosition = spreadPosition
		beam.Color = ColorSequence.new(Color3.fromRGB(243, 255, 8),Color3.fromRGB(251, 255, 0))
		beam.LightEmission = 1
		beam.LightInfluence = 0
		beam.Transparency = NumberSequence.new(0,1)
		beam.Attachment0 = script.Parent.Handle.BarrelAttachment
		beam.Attachment1 = attachment1
		beam.FaceCamera = true
		beam.Width0 = 0.175
		beam.Width1 = 0.175
		script.Parent.Handle.Fire1.PlaybackSpeed = 1 + math.random(-100,100)/1000
		script.Parent.Handle.Fire1:Play()
		script.Parent.Handle.Fire2.PlaybackSpeed = 1.25 + math.random(-100,100)/250
		script.Parent.Handle.Fire2:Play()
	end
end)
script.Parent.Activated:Connect(function()
	script.Parent.Activated:Connect(function()
		for _, ins in pairs(workspace:GetChildren()) do
			if ins:FindFirstChild("Humanoid") then
				for _, ins2 in pairs(ins:GetChildren()) do
					if ins2:IsA("Accessory") then
						if table.find(filterArray,ins2) == nil then
							table.insert(filterArray,ins2)
						end
					end
				end
			end
		end
		raycastParams.FilterDescendantsInstances = filterArray
	end)
end)
script.Parent.Equipped:Connect(function()
	equipped = true
	character = script.Parent.Parent
	if table.find(filterArray,script.Parent.Parent) == nil then
		table.insert(filterArray,script.Parent.Parent)
	end
	if table.find(filterArray,script.Parent) == nil then
		table.insert(filterArray,script.Parent)
	end
	raycastParams.FilterDescendantsInstances = filterArray
	if character then
		humanoid = character.Humanoid
		if humanoid:FindFirstChild("Animator") == nil then
			animator = Instance.new("Animator",humanoid)
		elseif humanoid:FindFirstChild("Animator") then
			animator = humanoid:FindFirstChild("Animator")
		end
	end
	animate = animator:LoadAnimation(script.Hold)
	animate:Play()
end)
script.Parent.Unequipped:Connect(function()
	equipped = false
	if script.Parent:FindFirstChild("Handle") then
		script.Parent.Handle.PointLight.Enabled = false
		script.Parent.Handle.BillboardGui.Enabled = false
	end
	for _, ins in pairs(script.Parent.Handle:GetChildren()) do
		if ins:IsA("Sound") then
			ins:Stop()
		elseif ins:IsA("PointLight") then
			ins.Enabled = false
		end
	end
	if animate then
		animate:Stop()
	end
	if animate2 then
		animate2:Stop()
	end
end)

Local Handler :

local mouse = game.Players.LocalPlayer:GetMouse()
local equipped = false
local connection
local connection2
local active = false
local debounce = false
script.Parent.Equipped:Connect(function()
	equipped = true
	connection = mouse.Button1Down:Connect(function()
		if equipped == true and debounce == false then
			active = true
			repeat
				if debounce == false then
					debounce = true
					local mousePos = mouse.Hit.Position
					script.Parent.RequestFire:FireServer(mousePos)
				end
				wait(0.6)
				debounce = false
			until active == false
		end
	end)
	connection2 = mouse.Button1Up:Connect(function()
		if equipped == true then
			active = false
		end
	end)
end)
script.Parent.Unequipped:Connect(function()
	equipped = false
	active = false
	connection:Disconnect()
	connection2:Disconnect()
end)


If You Can Help Please Reply. I Really Need Help For My DarkRP Game

How are you storing the data for each gun? Such as damage? I’d recommend using a ModuleScript to store information such as ReloadSpeed and such. No matter how you store it, you need to store the current mode of the gun.

Currently, from what it looks like, you got a fully-auto gun implemented. To make it semi you only have to add the following to your repeat statement:

repeat
    ... -- Your code
until active == false or fireMode == "semi"

This will prevent it from firing over and over.

Also, you should use task.wait() instead of wait. It is an improved version of wait().

1 Like

Its Still Auto, It Doesnt Prevent It From Firing It Over And Over. But I Appreciate Your Reply

Also I Need Help On This Part Aswell

Well, you can use boolean values or variables for changing modes and for recoil system there is a module called SpringModule.

There should be no difference between the recoil for semi or auto. The recoil effect should trigger per bullet. For example, camera moves up X degrees upon shooting once. Shooting 3 times in a row should then move it up by 3X degrees.

Also My Gun Isnt Semi Yet. Somehow Its Still Auto

It is because of Button1Down like it checks if the player is holding the mouse button.

So What Should I Replace Button1Down With ?

maybe try add another key to change mode
for example:Press v to change mode

Well All I Want Is To Make My Gun Semi And Thats All, Not Those Type Of Switching Modes Thing

Hmm, you can use UserInputService like Enum.UserInputType.MouseButton1 if you don’t understand let me give an example:

If you still did not understand I can teach you how to use UserInputService (UIS).