Advertisement
ElliscecieCreates

ServerSource - Kali - SG2

Jun 12th, 2025
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.45 KB | Gaming | 0 0
  1. --// Services
  2. local serverStorage = game:GetService("ServerStorage")
  3. local players = game:GetService("Players")
  4.  
  5. -- // Folders & Storages
  6. local eventsFolder = script.Parent:WaitForChild("Events")
  7. local valuesFolder = script.Parent:WaitForChild("Values")
  8. local soundsFolder = script.Parent:WaitForChild("Sounds")
  9. local accBank = serverStorage:WaitForChild("AccessoriesBank")
  10. local existingAcc = serverStorage:WaitForChild("ExistingAccessories")
  11.  
  12. -- // Accessories
  13. local leftHandKali = accBank:WaitForChild("KaliToolL"):Clone()
  14. local kaliUnequipAcc = accBank:WaitForChild("KaliAccUnequip"):Clone()
  15.  
  16. leftHandKali.Name = "KaliToolL"
  17. kaliUnequipAcc.Name = "KaliAccUnequip"
  18.  
  19. leftHandKali.Parent = existingAcc
  20. kaliUnequipAcc.Parent = existingAcc
  21.  
  22. -- // Events
  23. local playerBlockedAttack = eventsFolder:WaitForChild("PlayerBlockedAttack")
  24. local playerOpponentHit = eventsFolder:WaitForChild("PlayerOpponentHit")
  25. local beginBlocking = eventsFolder:WaitForChild("BeginBlocking")
  26. local destroyBlockOpponent = eventsFolder:WaitForChild("DestroyBlockOpp")
  27. local dialAttack = eventsFolder:WaitForChild("DialAttack")
  28. local dialDodge = eventsFolder:WaitForChild("DialDodge")
  29. local dialHeavy = eventsFolder:WaitForChild("DialHeavy")
  30. local dialSpecial = eventsFolder:WaitForChild("DialSpecial")
  31. local endBlocking = eventsFolder:WaitForChild("EndBlocking")
  32. local resetCombo = eventsFolder:WaitForChild("ResetCombo")
  33. local destroyBlockPlayer = eventsFolder:WaitForChild("DestroyBlockPlayer")
  34.  
  35. -- // Values
  36. local blockPower = valuesFolder:WaitForChild("BlockPower")
  37. local blockBrokenCooldown = valuesFolder:WaitForChild("BlockBrokenCooldown")
  38. local dodgeDashCooldown = valuesFolder:WaitForChild("DodgeDashCooldown")
  39. local blockCooldown = valuesFolder:WaitForChild("BlockCooldown")
  40. local attackCooldown = valuesFolder:WaitForChild("AttackCooldown")
  41. local isBlocking = valuesFolder:WaitForChild("IsBlocking")
  42. local maxBlockPower = valuesFolder:WaitForChild("MaxBlockPower")
  43. local specialCooldown = valuesFolder:WaitForChild("SpecialCooldown")
  44. local heavyCooldown = valuesFolder:WaitForChild("HeavyCooldown")
  45. local blockWasBroken = valuesFolder:WaitForChild("BlockWasBroken")
  46. local canAttack = valuesFolder:WaitForChild("CanAttack")
  47. local blockRegenTime = valuesFolder:WaitForChild("BlockRegenTime")
  48.  
  49. local normalAttackDamage = valuesFolder:WaitForChild("NormalAttackDamage").Value
  50. local specialAttackDamage = valuesFolder:WaitForChild("SpecialAttackDamage").Value
  51. local heavyAttackDamage = valuesFolder:WaitForChild("HeavyAttackDamage").Value
  52.  
  53. local rightKaliHitbox = script.Parent:WaitForChild("Handle"):WaitForChild("Hitbox")
  54. local leftKaliHitbox = leftHandKali:WaitForChild("Handle"):WaitForChild("Hitbox")
  55.  
  56. local attackIsFired = false
  57. local heavyIsFired = false
  58. local specialIsFired = false
  59. local hitTargets = {}
  60. local equippedPlayer = nil
  61. local equippedCharacter = nil
  62.  
  63. -- // Helper Functions
  64. local function getCharacter()
  65.     local parent = script.Parent.Parent
  66.     if parent and parent:FindFirstChild("Humanoid") then
  67.         return parent
  68.     end
  69.     return nil
  70. end
  71.  
  72. local function getPlayerFromCharacter(character)
  73.     return players:GetPlayerFromCharacter(character)
  74. end
  75.  
  76. local function tagHumanoid(humanoid, player)
  77.     if humanoid and player then
  78.         local existing = humanoid:FindFirstChild("creator")
  79.         if existing then existing:Destroy() end
  80.         local tag = Instance.new("ObjectValue")
  81.         tag.Name = "creator"
  82.         tag.Value = player
  83.         tag.Parent = humanoid
  84.         game:GetService("Debris"):AddItem(tag, 2)
  85.     end
  86. end
  87.  
  88. -- // Knockback Utility
  89. local function applyKnockback(targetHumanoid, distance, attackerHumanoid)
  90.     local rootPart = targetHumanoid.Parent:FindFirstChild("HumanoidRootPart")
  91.     if rootPart then
  92.         local direction = (attackerHumanoid and attackerHumanoid.Parent:FindFirstChild("HumanoidRootPart") and
  93.             (attackerHumanoid.Parent.HumanoidRootPart.CFrame.LookVector)) or rootPart.CFrame.LookVector
  94.         rootPart.Velocity = direction * distance * 10
  95.     end
  96.     if attackerHumanoid then
  97.         local attackerRoot = attackerHumanoid.Parent:FindFirstChild("HumanoidRootPart")
  98.         if attackerRoot then
  99.             attackerRoot.Velocity = attackerRoot.CFrame.LookVector * distance * 5
  100.         end
  101.     end
  102. end
  103.  
  104. -- // Hit Processing
  105. local function processHit(humanoid)
  106.     if not table.find(hitTargets, humanoid) then
  107.         table.insert(hitTargets, humanoid)
  108.         local character = getCharacter()
  109.         local player = getPlayerFromCharacter(character)
  110.         if player then tagHumanoid(humanoid, player) end
  111.         humanoid:TakeDamage(normalAttackDamage)
  112.         applyKnockback(humanoid, 1, character:FindFirstChild("Humanoid"))
  113.         soundsFolder:WaitForChild("Hit"..math.random(1,2)):Play()
  114.         local weapontool = humanoid.Parent and humanoid.Parent:FindFirstChildOfClass("Tool")
  115.         if weapontool then
  116.             weapontool:WaitForChild("Values"):WaitForChild("BlockPower").Value -= 1
  117.         end
  118.     end
  119. end
  120.  
  121. local function processHitHeavy(humanoid)
  122.     if not table.find(hitTargets, humanoid) then
  123.         table.insert(hitTargets, humanoid)
  124.         local character = getCharacter()
  125.         local player = getPlayerFromCharacter(character)
  126.         if player then tagHumanoid(humanoid, player) end
  127.         humanoid:TakeDamage(heavyAttackDamage)
  128.         applyKnockback(humanoid, 2, character:FindFirstChild("Humanoid"))
  129.         soundsFolder:WaitForChild("Hit"..math.random(1,2)):Play()
  130.         local weapontool = humanoid.Parent and humanoid.Parent:FindFirstChildOfClass("Tool")
  131.         if weapontool then
  132.             weapontool:WaitForChild("Values"):WaitForChild("BlockPower").Value -= 2
  133.         end
  134.     end
  135. end
  136.  
  137. local function processHitSpecial(humanoid)
  138.     if not table.find(hitTargets, humanoid) then
  139.         table.insert(hitTargets, humanoid)
  140.         local character = getCharacter()
  141.         local player = getPlayerFromCharacter(character)
  142.         if player then tagHumanoid(humanoid, player) end
  143.         humanoid:TakeDamage(specialAttackDamage)
  144.         applyKnockback(humanoid, 4.5, character:FindFirstChild("Humanoid"))
  145.         local char = humanoid.Parent
  146.         local weapontool = char and char:FindFirstChildOfClass("Tool")
  147.         local blockField = char and char:FindFirstChild("BlockField")
  148.         if weapontool then
  149.             weapontool:WaitForChild("Values"):WaitForChild("BlockPower").Value = 0
  150.         end
  151.         if blockField then
  152.             blockField:Destroy()
  153.             destroyBlockPlayer:FireClient(players:GetPlayerFromCharacter(char))
  154.         end
  155.     end
  156. end
  157.  
  158. local function onHitboxTouched(hit)
  159.     local character = getCharacter()
  160.     if hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= character then
  161.         local humanoid = hit.Parent:FindFirstChild("Humanoid")
  162.         if humanoid and canAttack.Value then
  163.             if attackIsFired then processHit(humanoid)
  164.             elseif heavyIsFired then processHitHeavy(humanoid)
  165.             elseif specialIsFired then processHitSpecial(humanoid) end
  166.         end
  167.     end
  168. end
  169.  
  170. rightKaliHitbox.Touched:Connect(onHitboxTouched)
  171. leftKaliHitbox.Touched:Connect(onHitboxTouched)
  172.  
  173. local function setupLimbHitbox(limb)
  174.     limb.Touched:Connect(function(hit)
  175.         onHitboxTouched(hit)
  176.     end)
  177. end
  178.  
  179. local function onCharacterRemoving(character)
  180.     if equippedCharacter == character then
  181.         local kaliEquipped = character:FindFirstChild("KaliToolL")
  182.         if kaliEquipped then kaliEquipped:Destroy() end
  183.         local blockField = character:FindFirstChild("BlockField")
  184.         if blockField then blockField:Destroy() end
  185.         equippedCharacter = nil
  186.         equippedPlayer = nil
  187.     end
  188. end
  189.  
  190. -- // Equip
  191. script.Parent.Equipped:Connect(function()
  192.     local tool = script.Parent
  193.     local character = tool.Parent
  194.     local player = players:GetPlayerFromCharacter(character)
  195.  
  196.     canAttack.Value = true
  197.  
  198.     if player and character then
  199.         equippedPlayer = player
  200.         equippedCharacter = character
  201.         player.CharacterRemoving:Connect(onCharacterRemoving)
  202.         local rightArm = character:FindFirstChild("RightArm") or character:FindFirstChild("RightHand")
  203.         local leftArm = character:FindFirstChild("LeftArm") or character:FindFirstChild("LeftHand")
  204.         if rightArm then setupLimbHitbox(rightArm) end
  205.         if leftArm then setupLimbHitbox(leftArm) end
  206.         local oldUnequipped = character:FindFirstChild("KaliAccUnequip")
  207.         if oldUnequipped then oldUnequipped:Destroy() end
  208.         local newKaliLeft = accBank:FindFirstChild("KaliToolL"):Clone()
  209.         newKaliLeft.Name = "KaliToolL"
  210.         newKaliLeft.Parent = character
  211.         tool:SetAttribute("EquippedLeftKaliName", newKaliLeft.Name)
  212.     else
  213.         warn("[Kali Equip] Failed to resolve character or player.")
  214.     end
  215. end)
  216.  
  217. -- // Unequip
  218. script.Parent.Unequipped:Connect(function()
  219.     canAttack.Value = false
  220.     attackIsFired = false
  221.     hitTargets = {}
  222.     if equippedPlayer and equippedCharacter then
  223.         local kaliEquipped = equippedCharacter:FindFirstChild("KaliToolL")
  224.         if kaliEquipped then kaliEquipped:Destroy() end
  225.         local newUnequipped = accBank:FindFirstChild("KaliAccUnequip"):Clone()
  226.         newUnequipped.Name = "KaliAccUnequip"
  227.         newUnequipped.Parent = equippedCharacter
  228.     else
  229.         warn("[Kali Unequip] Player or character reference missing.")
  230.     end
  231.     equippedPlayer = nil
  232.     equippedCharacter = nil
  233. end)
  234.  
  235. -- // Blocking Events
  236. beginBlocking.OnServerEvent:Connect(function()
  237.     local character = getCharacter()
  238.     if character and not character:FindFirstChild("BlockField") then
  239.         local blockField = Instance.new("ForceField")
  240.         blockField.Name = "BlockField"
  241.         blockField.Visible = true
  242.         blockField.Parent = character
  243.     end
  244.     isBlocking.Value = true
  245. end)
  246.  
  247. endBlocking.OnServerEvent:Connect(function()
  248.     local character = getCharacter()
  249.     local blockField = character and character:FindFirstChild("BlockField")
  250.     if blockField then blockField:Destroy() end
  251.     isBlocking.Value = false
  252. end)
  253.  
  254. destroyBlockOpponent.OnServerEvent:Connect(function(_, opponent)
  255.     if opponent and opponent:IsA("Player") then
  256.         local character = opponent.Character
  257.         if character then
  258.             local blockField = character:FindFirstChild("BlockField")
  259.             if blockField then blockField:Destroy() end
  260.             local hum = character:FindFirstChild("Humanoid")
  261.             if hum then hum:TakeDamage(normalAttackDamage / 2) end
  262.         end
  263.     end
  264. end)
  265.  
  266. local function resetAttackFlags()
  267.     attackIsFired = false
  268.     heavyIsFired = false
  269.     specialIsFired = false
  270. end
  271.  
  272. dialAttack.OnServerEvent:Connect(function()
  273.     resetAttackFlags()
  274.     attackIsFired = true
  275.     hitTargets = {}
  276. end)
  277.  
  278. dialHeavy.OnServerEvent:Connect(function()
  279.     resetAttackFlags()
  280.     heavyIsFired = true
  281.     hitTargets = {}
  282. end)
  283.  
  284. dialSpecial.OnServerEvent:Connect(function()
  285.     resetAttackFlags()
  286.     specialIsFired = true
  287.     hitTargets = {}
  288. end)
  289.  
  290. -- // Block Regen
  291. task.spawn(function()
  292.     while task.wait(blockRegenTime.Value) do
  293.         if blockPower.Value < maxBlockPower.Value then
  294.             blockPower.Value = math.min(blockPower.Value + 1, maxBlockPower.Value)
  295.         end
  296.     end
  297. end)
  298.  
Tags: combat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement