Cakey3101

Battlegrounds - Input (30)

Oct 1st, 2025
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.74 KB | Source Code | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local Players = game:GetService("Players")
  4. local Debris = game:GetService("Debris")
  5. local Workspace = game:GetService("Workspace")
  6.  
  7. local HitboxModule = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("HitboxModule"))
  8. local Config = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("Config"))
  9. local Remotes = ReplicatedStorage:WaitForChild("Remotes")
  10.  
  11. local Player = Players.LocalPlayer
  12. local PlayerGui = Player.PlayerGui
  13. local MobileUI = PlayerGui:WaitForChild("MobileUI")
  14. local MainFrame_Mobile = MobileUI:WaitForChild("Main")
  15.  
  16. local Attack_Mobile = MainFrame_Mobile:WaitForChild("Attack")
  17. local Block_Mobile = MainFrame_Mobile:WaitForChild("Block")
  18.  
  19. local Temp = {}
  20.  
  21. local Character: Model, Humanoid: Humanoid, Animator: Animator
  22.  
  23. local AnimPrefix = "rbxassetid://"
  24. local HitAnimationId = 85710625600514
  25. local DownslamAnimationId = 132755135725741
  26. local UppercutAnimationId = 97693103786628
  27. local BlockingAnimTrack
  28.  
  29. local Data = {
  30.     Punch = {
  31.         OnDebounce = false;
  32.         DebounceTime = 0.5;
  33.         MaxDebounceTime = 1.5;
  34.         OnNum = 0;
  35.         MaxNum = 4;
  36.         HitPlayers = {};
  37.         BlockingPlayers = {};
  38.         ResetTime = 2;
  39.         PunchThread = nil;
  40.         LastPunchTime = 0;
  41.         Uppercut = false;
  42.     },
  43. }
  44.  
  45. local function OnCharacterAdded(Char: Model)
  46.     Character = Char :: Model
  47.     Humanoid = Character:WaitForChild("Humanoid") :: Humanoid
  48.     Animator = Humanoid:WaitForChild("Animator") :: Animator
  49. end
  50.  
  51. OnCharacterAdded(Player.Character or Player.CharacterAdded:Wait())
  52.  
  53. local function PlayAnim(Id: string)
  54.     local AnimId = AnimPrefix..Id
  55.  
  56.     local Animation = Instance.new("Animation")
  57.     Animation.AnimationId = AnimId
  58.  
  59.     local AnimTrack = Animator:LoadAnimation(Animation)
  60.  
  61.     AnimTrack:Play()
  62. end
  63.  
  64. local function CheckMobile()
  65.     if UserInputService.TouchEnabled then
  66.         MobileUI.Enabled = true
  67.     end
  68. end
  69.  
  70. local function IsInAir()
  71.     local S = Humanoid:GetState()
  72.    
  73.     return (S == Enum.HumanoidStateType.Freefall or
  74.         S == Enum.HumanoidStateType.FallingDown or
  75.         S == Enum.HumanoidStateType.Jumping)
  76. end
  77.  
  78. local function GetState()
  79.     if IsInAir() and Data.Punch.OnNum == Data.Punch.MaxNum then
  80.         warn("Downslam")
  81.         return "Slam"
  82.     end
  83.    
  84.     return "Normal"
  85. end
  86.  
  87. local function _Input(Plr: Player, Char: Model)
  88.     if Humanoid and Humanoid.Health <= 0 then
  89.         return
  90.     end
  91.    
  92.     local SelectedChar, CharDataTable = Remotes.GetCharacterInfo:InvokeServer()
  93.     if not (SelectedChar and CharDataTable) then return end
  94.     if Data.Punch.OnDebounce then return end
  95.  
  96.     Data.Punch.OnDebounce = true
  97.  
  98.     if Data.Punch.OnNum + 1 > Data.Punch.MaxNum then
  99.         Data.Punch.OnNum = 1
  100.     else
  101.         Data.Punch.OnNum += 1
  102.     end
  103.  
  104.     local State = GetState()
  105.     if Data.Punch.Uppercut then
  106.         State = "Uppercut"
  107.     end
  108.    
  109.     Data.Punch.LastPunchTime = tick()
  110.    
  111.     if State == "Slam" then
  112.         PlayAnim(DownslamAnimationId)
  113.     elseif State == "Uppercut" then
  114.         PlayAnim(UppercutAnimationId)
  115.     else
  116.         local AnimId = CharDataTable.Animations.PunchAnimations[Data.Punch.OnNum]
  117.         if AnimId then
  118.             PlayAnim(AnimId)
  119.         end
  120.     end
  121.    
  122.     Remotes.Attack:FireServer(Data.Punch.OnNum, State)
  123.    
  124.     if Data.Punch.PunchThread then
  125.         task.cancel(Data.Punch.PunchThread)
  126.     end
  127.    
  128.     Data.Punch.PunchThread = task.delay(Data.Punch.ResetTime, function()
  129.         Data.Punch.OnNum = 0
  130.         Data.Punch.PunchThread = nil
  131.     end)
  132.    
  133.     local WaitTime = (Data.Punch.OnNum == Data.Punch.MaxNum) and Data.Punch.MaxDebounceTime or Data.Punch.DebounceTime
  134.    
  135.     task.delay(WaitTime, function()
  136.         Data.Punch.OnDebounce = false
  137.     end)
  138. end
  139.  
  140. CheckMobile()
  141.  
  142. local function _Block(Plr: Player, Hum: Humanoid, IsBlocking: boolean)
  143.     Remotes.Block:FireServer(IsBlocking)
  144.  
  145.     if IsBlocking then
  146.         local SelectedCharacter = Player.SelectedCharacter.Value
  147.         local Character = Player.Character
  148.         if SelectedCharacter then
  149.             local CharModule = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("CharacterModule"):WaitForChild("Characters")[SelectedCharacter])
  150.             if CharModule then
  151.                 local BlockingAnim = CharModule.Animations.Blocking
  152.                 if BlockingAnim then
  153.                     local AnimId = AnimPrefix .. BlockingAnim
  154.                     local Animation = Instance.new("Animation")
  155.                     Animation.AnimationId = AnimId
  156.  
  157.                     BlockingAnimTrack = Animator:LoadAnimation(Animation)
  158.                     BlockingAnimTrack:Play()
  159.                 end
  160.             end
  161.         end
  162.     else
  163.         if BlockingAnimTrack then
  164.             BlockingAnimTrack:Stop()
  165.         end
  166.     end
  167. end
  168.  
  169. Attack_Mobile.MouseButton1Click:Connect(function()
  170.     _Input(Player, Character)
  171. end)
  172.  
  173. Block_Mobile.MouseButton1Down:Connect(function()
  174.     _Block(Player, Humanoid, true)
  175. end)
  176.  
  177. Block_Mobile.MouseButton1Up:Connect(function()
  178.     _Block(Player, Humanoid, false)
  179. end)
  180.  
  181. Block_Mobile.MouseLeave:Connect(function()
  182.     _Block(Player, Humanoid, false)
  183. end)
  184.  
  185. UserInputService.InputBegan:Connect(function(Input: InputObject, GameProcessedEvent: boolean)
  186.     if GameProcessedEvent then return end
  187.  
  188.     if Input.UserInputType == Enum.UserInputType.MouseButton1 then
  189.         _Input(Player, Character)
  190.     end
  191.  
  192.     if Input.KeyCode == Enum.KeyCode.F then
  193.         _Block(Player, Humanoid, true)
  194.     end
  195.  
  196.     if Input.UserInputType == Enum.UserInputType.Touch then
  197.         _Block(Player, Humanoid, false)
  198.     end
  199.    
  200.     if Input.KeyCode == Enum.KeyCode.Space then
  201.         local DT = tick() - Data.Punch.LastPunchTime
  202.         if DT <= 0.5 and Data.Punch.OnNum == Data.Punch.MaxNum then
  203.             warn("Uppercut")
  204.             Data.Punch.Uppercut = true
  205.             _Input(Player, Character)
  206.             Data.Punch.Uppercut = false
  207.         end
  208.     end
  209. end)
  210.  
  211. UserInputService.InputEnded:Connect(function(Input: InputObject, GameProcessedEvent: boolean)
  212.     if GameProcessedEvent then return end
  213.  
  214.     if Input.KeyCode == Enum.KeyCode.F then
  215.         _Block(Player, Humanoid, false)
  216.     end
  217. end)
  218.  
  219. Player.CharacterAdded:Connect(OnCharacterAdded)
Advertisement
Add Comment
Please, Sign In to add comment