;-;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)```