2 barrels, firing 4 bullets..? <-- solved)) How do I get this direction?

1-
2 barrel pieces, game decides to shoot 4, any method of debounce?

		for i,v in pairs(Handle:GetChildren()) do
				if v.Name ~= 'GunFirePoint' then continue end
				local mouseDirection = v.Position.Unit
				Fire(mouseDirection)
			end

2-

local mouseDirection = v.Position.Unit

How do I set the direction to be what the barrel piece is facing…?

can we get the full script maybe?

Any reason why?

Literally just trying to find a method for debounce according to how many barrel parts there are…

To add debounce char limitt

This is literally the only part that matters… Other parts of the script are sorta unrelated.

MouseEvent.OnServerEvent:Connect(function (clientThatFired, mousePoint)
	if CurrentAmmo.Value ~= 0 then
		if not CanFire then
			return
		end
		CanFire = false
		if CurrentAmmo.Value > MinAmmo.Value then
			CurrentAmmo.Value -= 1
		end
		if CurrentAmmo.Value == 0 then
			CanFire = false
		end
		for i = 1, BULLETS_PER_SHOT do
			local muzzle = math.random(0, 1)
			if muzzle == 0 then
				FirePointObject.Muzzle.Enabled = false
			elseif muzzle == 1 then
				FirePointObject.Muzzle.Enabled = true
			end
			for i,v in pairs(Handle:GetChildren()) do
				if v.Name ~= 'GunFirePoint' then continue end
				local mouseDirection = v.Position.Unit
				Fire(mouseDirection)
			end
			wait(0.01)
			FirePointObject.Muzzle.Enabled = false
		end
		if FIRE_DELAY > 0.03 and CurrentAmmo.Value > MinAmmo.Value and CurrentAmmo.Value ~= 0 then wait(FIRE_DELAY) end
		CanFire = true
	elseif CurrentAmmo.Value == 0 then
		if EmptySound.Playing == false then
			EmptySound:Play()
			wait(1)
		end
	end
end)

well if it is triggered by a click of the mouse that fires a remote event then the remote is being fired 4 times? Is the issue that when you click once it shoots twice the intended amount?

I have an idea… Hold on let me make the script…

Nevermind, I can’t figure it out…

1 Like

If you want to add debounce you can do something like this:

local db = 0

if tick() - db < 3 then
	return
end
db = tick()
--Run code here

this should be In the script that fires the event btw

That didn’t work… BUT, I found something, so basically I put it to print everytime it finds a barrel part, and it printed 4 times… I’m gonna test how much it increases depending on the amount of barrels so maybe I can do some math to reduce it to the proper amount.

can you show me where you put it in the script?

Wait… I found my mistake… I had 2 extra attachments named the same thing… Oops!

OK, now, for the 2nd part… How do get the direction that the parts are facing?

It probably did work though, just had 4 different things named that.

to make something do the direction you can get its lookvector and multipy it by how many studs in that direction you want it to fire, example:

barrel.CFrame.LookVector*100

Doesn’t seem to be working…

Here’s what the original script looks like:

local mouseDirection = (mousePoint - FirePointObject.WorldPosition).Unit
	for i = 1, BULLETS_PER_SHOT do
		Fire(mouseDirection)
	end

have u defined barrel? char limit

			for i,v in pairs(Handle:GetChildren()) do
				if v.Name ~= 'GunFirePoint' then continue end

Forget this, I don’t know what to do anymore, got someone else helping me.