local RunService = game:GetService("RunService") local Players = game:GetService("Players") local GunModule = require(game.ServerScriptService.MainGunModule) local Components = script.Parent.Parent.Components local Turret = script.Parent.TurretGroup local Hull = script.Parent.Hull local Gun = Turret.BarrelGroup.BarrelParts.Barrel.MainBarrel local TurretSeat = Turret.TurretSeat local GunEffects = script.Parent.Parent.Effects -- Configs local CurrSpeed = 0 local CurrTurn = 0 local OldSpeed = 0 local MaxFSpeed = 50 local MaxBSpeed = 26 local RotSpeed = 0.5 local TurnAdder = 0.25 local SpeedAdder = 0.15 local EffectTime = 0.2 local CanShoot = true local DB = false local PlayerGui = nil local WaitTime local plr local TankInfo = { Ammo = { APFSDS_M833 = true, HEAT_M456 = true, } } local TankInfoForClient = { Ammo = { "APFSDS_M833", "HEAT_M456", } } -- Event Functions game.ReplicatedStorage.FireGunServer.Event:Connect(function(Tank,Gun,AmmoType) if Tank == script.Parent.Parent then if CanShoot == true then CanShoot = false local CutAmmoType = string.split(AmmoType,"_")[2] local plr = game.Players[Tank.Tank.TurretGroup.TurretSeat.Occupant.Parent.Name] for _,v in pairs(Turret.TurretBase.Ammo:GetChildren()) do if v:IsA("Model") then if string.find(v.Name,CutAmmoType) then if #v:GetChildren() ~= 0 then if DB == false then DB = true WaitTime = GunModule.Fire(Tank,Gun,AmmoType) game.ReplicatedStorage.ReloadAnimation:FireClient(plr,WaitTime) coroutine.resume(coroutine.create(function() if GunEffects then task.wait() GunEffects.MuzzleFlash.SmokeFX:Emit(100) GunEffects.MuzzleFlash.FireFX.Enabled = true task.wait(EffectTime) GunEffects.MuzzleFlash.FireFX.Enabled = false end end)) Components.BlastDoorOpen.Value = true local Part = v:GetChildren()[math.random(1,#v:GetChildren())] Part:Destroy() end end end end end task.wait(WaitTime) Components.BlastDoorOpen.Value = false CanShoot = true DB = false end end end) -- Functions local Stop = function() local Speed = TurretSeat.Velocity.magnitude if Speed < 3 then CurrSpeed = 0 else CurrSpeed = (Speed - SpeedAdder*5) * CurrSpeed/math.abs(CurrSpeed) end end -- Loops RunService.Stepped:Connect(function(DeltaTime) if TurretSeat then if TurretSeat.Occupant then plr = game.Players:FindFirstChild(TurretSeat.Occupant.Parent.Name) TurretSeat.Occupant.UseJumpPower = true TurretSeat.Occupant.JumpPower = 0 local PitchConfigValue = 400 local Speed = math.round(TurretSeat.Velocity.Magnitude) local Pitch = math.clamp(math.round((1 + Speed/PitchConfigValue)*PitchConfigValue)/PitchConfigValue, 0.9, 1.2) Hull.EngineModel.Sound.PlaybackSpeed = Pitch game.ReplicatedStorage.OccupantChanged:FireClient(plr,script.Parent.Parent,TankInfoForClient,true) else if plr then GunModule.DestroyTank(script.Parent.Parent) game.ReplicatedStorage.OccupantChanged:FireClient(plr,script.Parent.Parent,TankInfoForClient,false) end end end end) coroutine.resume(coroutine.create(function() while task.wait() do if TurretSeat.Steer == 1 then CurrTurn = CurrTurn - TurnAdder elseif TurretSeat.Steer == -1 then CurrTurn = CurrTurn + TurnAdder elseif TurretSeat.Steer == 0 then if CurrTurn > 0 then CurrTurn = CurrTurn - TurnAdder if CurrTurn < 0 then CurrTurn = 0 end elseif CurrTurn < 0 then CurrTurn = CurrTurn + TurnAdder if CurrTurn > 0 then CurrTurn = 0 end elseif CurrTurn == 0 then CurrTurn = 0 end end if CurrTurn > RotSpeed then CurrTurn = RotSpeed elseif CurrTurn < -RotSpeed then CurrTurn = -RotSpeed end if TurretSeat.Throttle == 1 then if CurrSpeed > 0 then CurrSpeed = CurrSpeed + SpeedAdder*2 else CurrSpeed = CurrSpeed + SpeedAdder*3 end elseif TurretSeat.Throttle == -1 then if CurrSpeed < 0 then CurrSpeed = CurrSpeed - SpeedAdder else CurrSpeed = CurrSpeed - 5 if CurrSpeed > MaxFSpeed then CurrSpeed = MaxFSpeed end end end if CurrSpeed > MaxFSpeed then CurrSpeed = MaxFSpeed elseif CurrSpeed < -MaxBSpeed then CurrSpeed = -MaxBSpeed end if TurretSeat.Throttle == 0 and CurrSpeed ~= 0 then Stop() end local Dir = script.Parent.Hull.PrimaryPart.CFrame.LookVector script.Parent.Hull.PrimaryPart.BodyVelocity.Velocity = Dir*Vector3.new(CurrSpeed,CurrSpeed,CurrSpeed) script.Parent.Hull.PrimaryPart.BodyAngularVelocity.AngularVelocity = Vector3.new(0,CurrTurn,0) end end))