Cakey3101

Battlegrounds - Server (30)

Oct 1st, 2025
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.40 KB | Source Code | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2. local Players = game:GetService("Players")
  3. local Workspace = game:GetService("Workspace")
  4. local ServerScriptService = game:GetService("ServerScriptService")
  5. local MarketplaceService = game:GetService("MarketplaceService")
  6. local Debris = game:GetService("Debris")
  7.  
  8. local DataManager = require(ServerScriptService:WaitForChild("Modules"):WaitForChild("DataManager"))
  9. local CharacterModule = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("CharacterModule"))
  10. local StunModule = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("StunModule"))
  11. local AbilityModule = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("AbilityModule"))
  12. local ApplyKnockback = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("ApplyKnockBack"))
  13. local ApplyDamage = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("ApplyDamage"))
  14. local Config = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("Config"))
  15.  
  16. local HIT_ANIM_ID = 85710625600514
  17.  
  18. local Remotes = ReplicatedStorage:WaitForChild("Remotes")
  19. local CharactersFolder = ReplicatedStorage:WaitForChild("Modules"):WaitForChild("CharacterModule"):WaitForChild("Characters")
  20.  
  21. local OverlapParameters = OverlapParams.new()
  22. OverlapParameters.FilterType = Enum.RaycastFilterType.Exclude
  23. OverlapParameters.FilterDescendantsInstances = {}
  24. OverlapParameters.CollisionGroup = "Default"
  25.  
  26. local function ApplyAnimations(Player: Player, Character: string)
  27.     local CharacterInstance = CharactersFolder:WaitForChild(Character)
  28.    
  29.     if CharacterInstance then
  30.         local CharAnimate = CharacterInstance:FindFirstChild("Animate"):Clone()
  31.         local PlayerAnimate = Player.Character:FindFirstChild("Animate")
  32.        
  33.         if CharAnimate and PlayerAnimate then
  34.             CharAnimate.Parent = Player.Character
  35.             PlayerAnimate:Destroy()
  36.         end
  37.     else
  38.         warn("Character Instance Not Found", Character)
  39.     end
  40. end
  41.  
  42. local function Preload(Player: Player)
  43.     local Character = Player.Character
  44.     local Humanoid = Character:FindFirstChildOfClass("Humanoid")
  45.     local Animator = Humanoid:FindFirstChildOfClass("Animator")
  46.    
  47.     for _, Module: ModuleScript in CharactersFolder:GetChildren() do
  48.         if Module:IsA("ModuleScript") then
  49.             local RequiredModule = require(Module)
  50.             local Animations = RequiredModule.Animations
  51.            
  52.             for Name: string, Animation: number in pairs(Animations) do
  53.                 if Name == "PunchAnimations" then
  54.                     for AbilityNum, PunchAnimation: number in pairs(Animation) do
  55.                         local Anim = Instance.new("Animation")
  56.                         Anim.AnimationId = `rbxassetid://{PunchAnimation}`
  57.                        
  58.                         Animator:LoadAnimation(Anim)
  59.                     end
  60.                 else
  61.                     local Anim = Instance.new("Animation")
  62.                     Anim.AnimationId = `rbxassetid://{Animation}`
  63.  
  64.                     Animator:LoadAnimation(Anim)
  65.                 end
  66.             end
  67.         end
  68.     end
  69. end
  70.  
  71. local function ApplyCosmetics(Player: Player, Character: string)
  72.     local CharacterInstance = CharactersFolder:WaitForChild(Character)
  73.  
  74.     if CharacterInstance then
  75.         local Accessories = CharacterInstance:FindFirstChild("Accessories")
  76.        
  77.         local TempFolder = Player.Character:FindFirstChild("TempAccessories") or Instance.new("Folder")
  78.         TempFolder.Name = "TempAccessories"
  79.         TempFolder.Parent = Player.Character
  80.        
  81.         for _, Object in TempFolder:GetChildren() do
  82.             Object:Destroy()
  83.         end
  84.        
  85.         if Accessories then
  86.             for _, AccessoryFolder in ipairs(Accessories:GetChildren()) do
  87.                 if AccessoryFolder:IsA("Model") and AccessoryFolder.Name == "Accessory Template Dummy" then
  88.                     for _, BodyPart in AccessoryFolder:GetChildren() do
  89.                         local FakeBodyPart: BasePart = BodyPart:Clone()
  90.                         FakeBodyPart.Position = Player.Character[BodyPart.Name].Position
  91.                         FakeBodyPart.Orientation = Player.Character[BodyPart.Name].Orientation
  92.                        
  93.                         local Weld = Instance.new("WeldConstraint")
  94.                         Weld.Parent = FakeBodyPart
  95.                         Weld.Part0 = Player.Character[BodyPart.Name]
  96.                         Weld.Part1 = FakeBodyPart
  97.                        
  98.                         FakeBodyPart.Transparency = 1
  99.                         FakeBodyPart.Parent = TempFolder
  100.                     end
  101.                 end
  102.             end
  103.         end
  104.     else
  105.         warn("Character Instance Not Found", Character)
  106.     end
  107. end
  108.  
  109. local function ApplyCharacterStats(Player: Player, CharacterTable)
  110.     Player:SetAttribute("Atk_Dmg", CharacterTable.Atk.Dmg)
  111.     Player:SetAttribute("Health", CharacterTable.Health)
  112.     Player:SetAttribute("WalkSpeed_Mult", CharacterTable.SpeedMult)
  113.    
  114.     local Character = Player.Character
  115.    
  116.     Character:SetAttribute("LastHitBy", "")
  117.    
  118.     local Humanoid: Humanoid = Character:FindFirstChildOfClass("Humanoid")
  119.    
  120.     if Humanoid then
  121.         Humanoid.WalkSpeed = Config.NormalWalkSpeed * CharacterTable.SpeedMult
  122.         Humanoid.MaxHealth = CharacterTable.Health
  123.         Humanoid.Health = CharacterTable.Health
  124.     else
  125.         warn("Humanoid Not Found In Character")
  126.     end
  127.    
  128.     Player.UltActive.Value = false
  129.    
  130.     AbilityModule:Cleanup(Player)
  131.    
  132.     task.wait(0.2)
  133.    
  134.     AbilityModule:SetupCharacter(Player, CharacterTable)
  135.     ApplyAnimations(Player, CharacterTable.Name)
  136.     ApplyCosmetics(Player, CharacterTable.Name)
  137. end
  138.  
  139. local function BoxCastTargets(AttackerChar: Model, Size: Vector3, ForwardOffset: number, Params: OverlapParams)
  140.     local HRP = AttackerChar:FindFirstChild("HumanoidRootPart")
  141.     if not HRP then return {} end
  142.  
  143.     local CF = HRP.CFrame * CFrame.new(0, 0, -ForwardOffset)
  144.  
  145.     return Workspace:GetPartBoundsInBox(CF, Size, Params)
  146. end
  147.  
  148. local function GetVictimCharacterFromPart(Part: BasePart)
  149.     if not Part then return nil end
  150.    
  151.     local M = Part:FindFirstAncestorOfClass("Model")
  152.     if not M then return nil end
  153.    
  154.     if M:FindFirstChildOfClass("Humanoid") then
  155.         return M
  156.     end
  157.    
  158.     return nil
  159. end
  160.  
  161. local function IsBlockingTarget(TargetChar: Model)
  162.     local Player = Players:GetPlayerFromCharacter(TargetChar)
  163.    
  164.     if Player then
  165.         return Player:GetAttribute("Blocking") == true
  166.     end
  167.    
  168.     local BV = TargetChar:FindFirstChild("Blocking")
  169.     return (BV and BV:IsA("BoolValue") and BV.Value) or false
  170. end
  171.  
  172. local function AttachBlockVFX(TargetChar: Model)
  173.     local VFXPart = ReplicatedStorage:FindFirstChild("VFX") and ReplicatedStorage.VFX:FindFirstChild("Block")
  174.     if not VFXPart then return end
  175.    
  176.     local HRP = TargetChar:FindFirstChild("HumanoidRootPart")
  177.     if not HRP then return end
  178.    
  179.     local Clone = VFXPart:Clone()
  180.     Clone.CFrame = HRP.CFrame
  181.     Clone.Parent = TargetChar
  182.    
  183.     local Weld = Instance.new("WeldConstraint", Clone)
  184.     Weld.Part0 = HRP
  185.     Weld.Part1 = Clone
  186.    
  187.     local Attachment = Clone:FindFirstChildOfClass("Attachment")
  188.    
  189.     if Attachment then
  190.         for _, V in ipairs(Attachment:GetChildren()) do
  191.             if V:IsA("ParticleEmitter") then
  192.                 V:Emit(1)
  193.             end
  194.         end
  195.     end
  196.    
  197.     Debris:AddItem(Clone, 2)
  198. end
  199.  
  200. local function ApplyM1Results(Attacker: Player, VictimChar: Model, Damage: number, KBRange: number, KBHeight: number, Heavy: boolean)
  201.     if not VictimChar then
  202.         return
  203.     end
  204.    
  205.     local Hum = VictimChar:FindFirstChildOfClass("Humanoid")
  206.     if not Hum then
  207.         return
  208.     end
  209.    
  210.     VictimChar:SetAttribute("LastHitBy", Attacker.Name)
  211.    
  212.     if IsBlockingTarget(VictimChar) then
  213.         StunModule.HitEffectsBlocking(VictimChar)
  214.         AttachBlockVFX(VictimChar)
  215.         return
  216.     end
  217.    
  218.     Hum:TakeDamage(Damage)
  219.     Attacker.UltPoints.Value += (Damage ^ 1.05)
  220.    
  221.     StunModule.ApplyStunAndEffects(VictimChar, 1, HIT_ANIM_ID, true, true)
  222.    
  223.     local AttackerChar = Attacker.Character
  224.     if AttackerChar then
  225.         local KB = ApplyKnockback.new(VictimChar, AttackerChar, KBRange, KBHeight)
  226.         KB:Construct()
  227.     end
  228.    
  229.     if Heavy then
  230.         local Rag = VictimChar:FindFirstChild("IsRagdoll")
  231.         if Rag and Rag:IsA("BoolValue") then
  232.             Rag.Value = true
  233.            
  234.             task.delay(1, function()
  235.                 if Rag then
  236.                     Rag.Value = false
  237.                 end
  238.             end)
  239.         end
  240.     end
  241. end
  242.  
  243. Players.PlayerAdded:Connect(function(Player: Player)
  244.     local Characters = CharacterModule.GetCharacters(Player)
  245.    
  246.     local SelectedCharacter = Player:WaitForChild("SelectedCharacter").Value
  247.     local CharInfo = CharacterModule.GetCharacterInfo(Player, SelectedCharacter)
  248.    
  249.     local function ApplyStatsOnRespawn()
  250.         local Character = Player.Character or Player.CharacterAdded:Wait()
  251.         local Humanoid: Humanoid = Character:FindFirstChild("Humanoid")
  252.        
  253.         ApplyCharacterStats(Player, CharInfo)
  254.         Preload(Player)
  255.        
  256.         Humanoid.Died:Connect(function()
  257.             Player.CharacterAdded:Wait()
  258.             ApplyCharacterStats(Player, CharInfo)
  259.         end)
  260.     end
  261.    
  262.     Remotes.ChangeCharacter:FireClient(Player, CharInfo)
  263.    
  264.     ApplyStatsOnRespawn()
  265. end)
  266.  
  267. Remotes.ChangeCharacter.OnServerEvent:Connect(function(Player: Player, Character: string)
  268.     if Player and Character then
  269.         if tostring(Player.SelectedCharacter.Value):lower() == tostring(Character):lower() then
  270.             warn(`Character: {tostring(Character)} Is Already Equipped!`)
  271.             return
  272.         end
  273.        
  274.         local Profile = DataManager.Profiles[Player]
  275.        
  276.         local CharInfo = CharacterModule.GetCharacterInfo(Player, Character)
  277.        
  278.         local GamepassID = 1448977557
  279.        
  280.         if CharInfo.OnEarlyAccess == true then
  281.             if not MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
  282.                 MarketplaceService:PromptGamePassPurchase(Player, GamepassID)
  283.                 return
  284.             end
  285.         end
  286.        
  287.         if ReplicatedStorage:WaitForChild("Modules"):WaitForChild("CharacterModule"):WaitForChild("Characters"):FindFirstChild(Character) then
  288.             Profile.Data.SelectedCharacter = Character
  289.             Player:WaitForChild("SelectedCharacter").Value = Profile.Data.SelectedCharacter
  290.            
  291.             Player:WaitForChild("UltPoints").Value = 0
  292.            
  293.             ApplyCharacterStats(Player, CharInfo)
  294.            
  295.             Remotes.ChangeCharacter:FireClient(Player, CharInfo)
  296.         end
  297.     end
  298. end)
  299.  
  300. Remotes.GetCharacterInfo.OnServerInvoke = function(Player: Player)
  301.     local SelectedChar = Player:WaitForChild("SelectedCharacter").Value
  302.    
  303.     local CharacterDataTable = CharacterModule.GetCharacterInfo(Player, SelectedChar)
  304.    
  305.     if SelectedChar and CharacterDataTable then
  306.         return SelectedChar, CharacterDataTable
  307.     else
  308.         return nil, {}
  309.     end
  310. end
  311.  
  312. Remotes.Ability.OnServerInvoke = function(Player: Player, AbilityName: string)
  313.     local SelectedCharacter = Player.SelectedCharacter.Value
  314.    
  315.     if CharactersFolder:FindFirstChild(SelectedCharacter) then
  316.         local CharModule = require(CharactersFolder[SelectedCharacter])
  317.         local CharModuleInstance = CharactersFolder[SelectedCharacter]
  318.         local Moveset
  319.         local AbilityInfoTable
  320.        
  321.         if Player.UltActive.Value then
  322.             Moveset = CharModule.UltMoveset
  323.         else
  324.             Moveset = CharModule.Moveset
  325.         end
  326.        
  327.         if Moveset then
  328.             for _, Move in pairs(Moveset) do
  329.                 if Move.Name == AbilityName then
  330.                     AbilityInfoTable = Move
  331.                     break
  332.                 end
  333.             end
  334.         end
  335.        
  336.         if AbilityInfoTable then
  337.             print(AbilityInfoTable)
  338.             return AbilityInfoTable
  339.         else
  340.             warn("Ability not found: " .. AbilityName)
  341.             return {}
  342.         end
  343.     else
  344.         warn("Selected Character Does Not Exist: " .. SelectedCharacter)
  345.     end
  346.    
  347.     return {}
  348. end
  349.  
  350. Remotes.FireAbility.OnServerEvent:Connect(function(Player: Player, AblityInfoTable)
  351.     local SelectedCharacter = Player.SelectedCharacter.Value
  352.    
  353.     if AblityInfoTable then
  354.         print(AblityInfoTable)
  355.         local CharModule = require(CharactersFolder[SelectedCharacter])
  356.         local CharModuleInstance = CharactersFolder[SelectedCharacter]
  357.        
  358.         local AbModule = require(CharModuleInstance.Abilities)
  359.         AbModule:Cast(Player, AblityInfoTable)
  360.     else
  361.         warn("Ability not found: " .. AblityInfoTable.Name)
  362.         return {}
  363.     end
  364. end)
  365.  
  366. Remotes.Knockback.OnServerEvent:Connect(function(Player: Player, EnemyCharacter: Model, Character: Model, Range: number, Height: number)
  367.     local Knockback = ApplyKnockback.new(EnemyCharacter, Character, Range, Height)
  368.     Knockback:Construct()
  369. end)
  370.  
  371. Remotes.Ragdoll.OnServerEvent:Connect(function(Player: Player, IsRagdollValue: BoolValue, Value: boolean)
  372.     IsRagdollValue.Value = Value
  373. end)
  374.  
  375. Remotes.Hit.OnServerEvent:Connect(function(Player: Player, EnemyCharacter: Model, AnimationId: number, Duration: number, Option: string, HitOption: boolean, AnimationOption: boolean)
  376.     if Option == "STUN" then
  377.         StunModule.StunFor(EnemyCharacter, Duration)
  378.     elseif Option == "HIT" then
  379.         StunModule.HitEffects(EnemyCharacter, AnimationId, HitOption, AnimationOption)
  380.     elseif Option == "BLOCKING" then
  381.         StunModule.HitEffectsBlocking(EnemyCharacter)
  382.     elseif Option == "BOTH" then
  383.         StunModule.ApplyStunAndEffects(EnemyCharacter, Duration, AnimationId, HitOption, AnimationOption)
  384.     end
  385.    
  386.     EnemyCharacter:SetAttribute("LastHitBy", Player.Name)
  387. end)
  388.  
  389. Remotes.Block.OnServerEvent:Connect(function(Player: Player, IsBlocking: boolean)
  390.     Player:SetAttribute("Blocking", IsBlocking == true)
  391. end)
  392.  
  393. Remotes.UltActivated.OnServerEvent:Connect(function(Player: Player)
  394.     local SelectedChar = Player:WaitForChild("SelectedCharacter").Value
  395.     local CharacterDataTable = CharacterModule.GetCharacterInfo(Player, SelectedChar)
  396.    
  397.     Player.UltPoints.Value = 0
  398.     Player.UltActive.Value = true
  399.    
  400.     AbilityModule:Cleanup(Player)
  401.     AbilityModule:SetupCharacter(Player, CharacterDataTable)
  402. end)
  403.  
  404. Remotes.UltEnded.OnServerEvent:Connect(function(Player: Player)
  405.     local SelectedChar = Player:WaitForChild("SelectedCharacter").Value
  406.     local CharacterDataTable = CharacterModule.GetCharacterInfo(Player, SelectedChar)
  407.  
  408.     Player.UltActive.Value = false
  409.  
  410.     AbilityModule:Cleanup(Player)
  411.     AbilityModule:SetupCharacter(Player, CharacterDataTable)
  412. end)
  413.  
  414. Remotes.AwardTakedown.OnServerEvent:Connect(function(Player: Player, PlayerToAwardTo: Player)
  415.     if Player and PlayerToAwardTo then
  416.         local Profile = DataManager.Profiles[PlayerToAwardTo]
  417.        
  418.         if Profile then
  419.             Profile.Data.TotalKills += 1
  420.             PlayerToAwardTo.leaderstats["Total Kills"].Value = Profile.Data.TotalKills
  421.            
  422.             PlayerToAwardTo.leaderstats.Kills.Value += 1
  423.         end
  424.     end
  425. end)
  426.  
  427. Remotes.Attack.OnServerEvent:Connect(function(Player: Player, ComboIndex: number, State: string)
  428.     local AttackerChar = Player.Character
  429.     local Hum = AttackerChar and AttackerChar:FindFirstChildOfClass("Humanoid")
  430.     local HRP = AttackerChar and AttackerChar:FindFirstChild("HumanoidRootPart")
  431.     if not (AttackerChar and Hum and HRP and Hum.Health > 0) then return end
  432.    
  433.     local SelectedChar = Player:FindFirstChild("SelectedCharacter") and Player.SelectedCharacter.Value
  434.     if not SelectedChar then return end
  435.    
  436.     local CharInfo = CharacterModule.GetCharacterInfo(Player, SelectedChar)
  437.     if not CharInfo or not CharInfo.Atk or not CharInfo.Atk.Dmg then return end
  438.    
  439.     local S = Hum:GetState()
  440.     if State == "Slam" then
  441.         local AirBorne = (S == Enum.HumanoidStateType.Freefall or S == Enum.HumanoidStateType.FallingDown or S == Enum.HumanoidStateType.Jumping)
  442.         if not AirBorne then
  443.             State = "Normal"
  444.         end
  445.     end
  446.    
  447.     OverlapParameters.FilterDescendantsInstances = { AttackerChar }
  448.    
  449.     local Size, Offset = Vector3.new(5, 5, 5), 4
  450.     local Heavy = false
  451.     local Dmg = CharInfo.Atk.Dmg
  452.     local KBRange, KBHeight = 10, 2
  453.    
  454.     if ComboIndex == 4 then
  455.         Heavy = true
  456.         Dmg *= Config.HeavyDmgMult
  457.        
  458.         if State == "Slam" then
  459.             Size = Vector3.new(5, 15, 5)
  460.             KBRange, KBHeight = 1, 5
  461.            
  462.         elseif State == "Uppercut" then
  463.             Size = Vector3.new(5, 5, 5)
  464.             KBRange, KBHeight = 1, 10
  465.         else
  466.             KBRange, KBHeight = 10, 2
  467.         end
  468.     else
  469.         Size = (State == "Uppercut")  and Vector3.new(5, 5, 5) or Vector3.new(5, 5, 5)
  470.         KBRange, KBHeight = 0, 0
  471.     end
  472.    
  473.     local Parts = BoxCastTargets(AttackerChar, Size, Offset, OverlapParameters)
  474.     local HitVictims = {}
  475.    
  476.     for _, P in ipairs(Parts) do
  477.         local VictimChar = GetVictimCharacterFromPart(P)
  478.         if VictimChar and VictimChar ~= AttackerChar and not HitVictims[VictimChar] then
  479.             HitVictims[VictimChar] = true
  480.             ApplyM1Results(Player, VictimChar, Dmg, KBRange, KBHeight, Heavy)
  481.         end
  482.     end
  483. end)
Advertisement
Add Comment
Please, Sign In to add comment