How do i make rifles?

  1. What do i want to achieve?
  • A bolt action rifle that doesn’t fire like an MG42
  • Rifle varieties (like semi-auto) (optional)
  1. What’s the problem?
  • To be honest, it will just complicates things so i just want ways and a fix just only for the problem that makes the rifle fires like an MG42 when mashing the left mouse key and like make it fire once even if the player is mashing the mouse button
  1. Extras
mouse.Button1Down:Connect(function()
	if isFiring then return end
	isFiring = true --// problem

	for i, v in pairs(framework.viewmodel:GetChildren()) do
		if v:IsA("Animation") then
			v.AnimationId = framework.module.animations.fire
			framework.viewmodel:WaitForChild("Humanoid"):LoadAnimation(v):Play()

			local sound = Instance.new("Sound", char.PrimaryPart)
			sound.SoundId = framework.module.sounds.fire
			sound.PlayOnRemove = true
			sound:Destroy()
		end
	end --// ignore this.

	task.wait(framework.module.FireTime) --// problem too
	isFiring = false --// problem again
end)

mouse.Button1Up:Connect(function()
	isFiring = false --// for SMGs or LMGs, but this isn't the issue tho. Trust me, it took me 10 hours.
end)

Note this is a StarterCharacterScript.
image

I would try for the RemoteEvent but I dont think it will be successful too…
For now please help me with this rifle-ish issue!

1 Like

Try if then statements?

Maybe they can detect wether the gun type is SMG or bolt action.

(Write the gun type inside the module I guess)

if isFiring then return end

This is the if then statement

That when it is fired, I mean this one

mouse.Button1Up:Connect(function()
	isFiring = false --// for SMGs or LMGs, but this isn't the issue tho. Trust me, it took me 10 hours.
end)

Wait everyone i got it cracked! turns out i just forgot to setup a debounce for the tool! here’s the final version

mouse.Button1Down:Connect(function()
	if isFiring or db then return end
	isFiring = true
	
	if framework.module.GunType == "rifleType" and isFiring and not db then
		isFiring = false
		db = true
		fire(framework.module.sounds.fire, framework.module.animations.fire, framework.viewmodel)
	end
	
	task.wait(framework.module.dbTime)
	isFiring = false
	db = false
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.