[[AAHHH THIS HAS BEEN KEEPING MY UP ALL NIGHT!] Minigun tool GONE WRONG

;-;im trying to make a super fast shooting turretn gear and ive spent 3 weeks perfecting da c pde but ihave some weirdo bugs that are really weird because lookinmg at the code this impossible

bugs: wen you exhaust all ammunition, you fire an extra round after tool gets off coldown!?
bugs: sometimes the camera lock doesnt stop when it supposed to

i tried it all

ok here the logic, dont worry it nopt allot

local script:

local US = game:GetService("UserInputService")
local player = game:GetService("Players")
local runtime = game:GetService("RunService")
local shot = tool.RemoteEvent
local play = tool["Justfor audio"]
local db = false -- soo endit al doesnt fire multiple time i think it does thattt and so you cannt shooot at zero ammo
local cameraLock = nil -- gattaling
local shooting = nil -- gatling
local Char = nil
local currentAnim = nil
local cooldown = 5
local rateOFFIREE = 0.1
local lastFire = 0
local Maxammunition = 69
local ammunition
local lerpyAlpha
local holding = false

local function endItAll(withToppings)
	if db then
		return
	end
	db = true
	US.MouseBehavior = Enum.MouseBehavior.Default
	workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	cameraLock:Disconnect()
	shooting:Disconnect()
	Char:FindFirstChildOfClass("Humanoid").HipHeight = 0
	Char:FindFirstChildOfClass("Humanoid").WalkSpeed = 21
	Char:FindFirstChildOfClass("Humanoid").JumpPower = 50
	Char:FindFirstChild("HumanoidRootPart").Anchored = false
	currentAnim:Stop()
	play:FireServer(tool["Truck Rev"])
	if withToppings then
		for i = cooldown, 1, -1 do
			tool.Name = i
			task.wait(1)
		end
	end
	cameraLock = nil
	tool.Name = "Gatling"
	db =false
end

local function snake()
	if ammunition == 0 then
		endItAll(true)
	end
	local Time = tick()

	if Time - lastFire >= rateOFFIREE and holding then
		lastFire = tick()
		shot:FireServer(player.LocalPlayer:GetMouse().Hit)
		ammunition -= 1
	end
end


tool.Activated:Connect(function()
	if not cameraLock then
		play:FireServer(tool["Robot Screams Processed Boar Squeals 6 (SFX)"])
		Char = tool.Parent
		Char:FindFirstChildOfClass("Humanoid").HipHeight = -0.1
		Char:FindFirstChildOfClass("Humanoid").WalkSpeed = 0
		Char:FindFirstChildOfClass("Humanoid").JumpPower = 0
		currentAnim = Char:FindFirstChildOfClass("Humanoid").Animator:LoadAnimation(script.init)
		currentAnim:Play()
		ammunition = Maxammunition
		lerpyAlpha = 0
		holding = false
		US.MouseBehavior = Enum.MouseBehavior.LockCenter
		--workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		task.wait(currentAnim.Length)
		currentAnim = Char:FindFirstChildOfClass("Humanoid").Animator:LoadAnimation(script.hover)
		currentAnim.Looped = true
		currentAnim:Play()
		play:FireServer(tool["Truck Rev"])
		Char:FindFirstChild("HumanoidRootPart").Anchored = true
		cameraLock = runtime.Heartbeat:Connect(function()
			Char.Head.CFrame = CFrame.lookAt(Char.Head.CFrame.Position, player.LocalPlayer:GetMouse().Hit.Position)
			--workspace.CurrentCamera.CFrame = Char:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(0,20,0)
		end)
		shooting = runtime.RenderStepped:Connect(snake)
	end
end)

tool.Unequipped:Connect(function()
	if cameraLock then
		endItAll(ammunition < Maxammunition)
	end
end)

US.InputBegan:Connect(function(input,IsTyping)
	if cameraLock == nil or input.UserInputType ~= Enum.UserInputType.MouseButton1 or IsTyping or db then
		return
	end
	holding = true
	snake()
end)

US.InputEnded:Connect(function(input, IsTyping)
	if cameraLock == nil or input.UserInputType ~= Enum.UserInputType.MouseButton1 or db then
		return
	end
	holding = false
end)```

SERVER SCRIPT....
```print("you need to have AAA OBJECT IN YOR STARTERCHARACTER... NAMED muzzle WITH AN ATTATCHMENT IN IT TF ARE YOU DOINGGG")

local shot = script.Parent.RemoteEvent
local mySounds = script.Parent["Justfor audio"]
local pea = game:GetService("ServerStorage")
local muzzle = nil -- muzle is thingy with attachment in side it 
local damage = 5

shot.OnServerEvent:Connect(function(plr, mouseHit)
	local audioWon = script.Parent["Machine Gun single shoot"]:Clone()
	local audioToo = script.Parent["pvz peashooter"]:Clone()
	audioWon.Parent = script.Parent
	audioWon:Play()
	game.Debris:AddItem(audioWon, audioWon.TimeLength)
	local projectile = pea.pee:Clone()
	projectile.CFrame = muzzle.WorldCFrame
	projectile.Parent = workspace
	projectile:ApplyImpulse(mouseHit.LookVector * 1000)
	projectile.Touched:Connect(function(touch)
		local humanoid = touch.Parent:FindFirstChildOfClass("Humanoid")
		local effect = pea.ParticleEmitter:Clone()
		local attach = Instance.new("Attachment")
		attach.CFrame = projectile.CFrame
		attach.Parent = workspace.Terrain
		effect.Parent = attach
		effect.Enabled = true
		if humanoid and humanoid.Parent.Name ~= muzzle.Name then
			humanoid:TakeDamage(damage)
			projectile:Destroy()
		end
		game.Debris:AddItem(attach, 0.5)
	end)
	game.Debris:AddItem(projectile, 5)
end)

mySounds.OnServerEvent:Connect(function(plr, audio: Sound)
	if not muzzle then
		muzzle = plr.Character.muzzle:FindFirstChildOfClass("Attachment")
		muzzle.Name = plr.Name
	end

	if audio.IsPlaying then
		audio:Stop()
	else
		audio:Play()
	end
end)```
1 Like

bro ive had this exact problem before and i forgot what i did to fix it

if Time - lastFire >= rateOFFIREE and holding then
		lastFire = tick()
		shot:FireServer(player.LocalPlayer:GetMouse().Hit)
		ammunition -= 1
	end

but try swapping the fireServer and ammunition

if Time - lastFire >= rateOFFIREE and holding then
		lastFire = tick()		
		ammunition -= 1
		shot:FireServer(player.LocalPlayer:GetMouse().Hit)
	end
US.InputBegan:Connect(function(input,IsTyping)
	if cameraLock == nil or input.UserInputType ~= Enum.UserInputType.MouseButton1 or IsTyping or db then
		return
	end
	holding = true
	snake()
end)

Why are you calling the snake() function here? It’s already being called in the Tool.Activated function…
(runtime.RenderStepped:Connect(snake))

Also can you explain abit more? After the cooldown does it just shoot again on it’s own or does it happen when you clicked or something

Also i think i know why the cameraLock sometimes doesn’t end up being brought back to normal.

You see in your Tool.Activated you wait for the currentAnim.Length and only after it’s finished you set the cameraLock and shooting. Could you just for the test remove that task.wait() and check if that changes anything?

i forgot

AAAAAAAAHDHDDDUUUUHUH AHEHHH AHHEEHHUUUUUEE

:sob:
uhh this not work. dang tuff that what this bug is

@ThtRookie it shot on it own

i might send roblox an email as this issue could be one on robloxx end…

1 Like

I don’t think that’d be effective at all…

Could you send a file with only the minigun tool (code, etc.)? Helping with this can be difficult as I can’t test it without remaking your project only based on the code and guessing along the way.

1 Like

ooh ohhh ok… @silver4804 @ThtRookie @
gattling gun.rbxm (7.0 KB)

reddetict will be fix code

also starrtter characte rmust have a p[art in it

GatlingGun_fixed.rbxl (74.5 KB)

This is what I have so far, it might still have some issues, but I’ve been working on it off and on for like 6-7 hours so low-key don’t want to work on it anymore. Understanding, formatting, testing, and rewriting takes a while.

There are different dependencies like a particle being under the projectile in ServerStorage instead of doing that through code. I’ve also tried to clean things up and generally follow naming conversions for readability.

I can recommend adding print statements throughout the process and seeing where issues arise from there.

1 Like

UUUUTS WORKING :smiley: AHEEEEH

Hahaaaa…
WOOOOHOOOOOO GFATTLING GUUUUNNNN
\I CAN PLAY GAAATLINGG GUU
!!! YEEHOOOO YEHOO YEHOO YEHOO YEHOO YEHOO YEHOO YEHOO

1 Like