Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Services
- local serverStorage = game:GetService("ServerStorage")
- local players = game:GetService("Players")
- -- // Folders & Storages
- local eventsFolder = script.Parent:WaitForChild("Events")
- local valuesFolder = script.Parent:WaitForChild("Values")
- local soundsFolder = script.Parent:WaitForChild("Sounds")
- local accBank = serverStorage:WaitForChild("AccessoriesBank")
- local existingAcc = serverStorage:WaitForChild("ExistingAccessories")
- -- // Accessories
- local leftHandKali = accBank:WaitForChild("KaliToolL"):Clone()
- local kaliUnequipAcc = accBank:WaitForChild("KaliAccUnequip"):Clone()
- leftHandKali.Name = "KaliToolL"
- kaliUnequipAcc.Name = "KaliAccUnequip"
- leftHandKali.Parent = existingAcc
- kaliUnequipAcc.Parent = existingAcc
- -- // Events
- local playerBlockedAttack = eventsFolder:WaitForChild("PlayerBlockedAttack")
- local playerOpponentHit = eventsFolder:WaitForChild("PlayerOpponentHit")
- local beginBlocking = eventsFolder:WaitForChild("BeginBlocking")
- local destroyBlockOpponent = eventsFolder:WaitForChild("DestroyBlockOpp")
- local dialAttack = eventsFolder:WaitForChild("DialAttack")
- local dialDodge = eventsFolder:WaitForChild("DialDodge")
- local dialHeavy = eventsFolder:WaitForChild("DialHeavy")
- local dialSpecial = eventsFolder:WaitForChild("DialSpecial")
- local endBlocking = eventsFolder:WaitForChild("EndBlocking")
- local resetCombo = eventsFolder:WaitForChild("ResetCombo")
- local destroyBlockPlayer = eventsFolder:WaitForChild("DestroyBlockPlayer")
- -- // Values
- local blockPower = valuesFolder:WaitForChild("BlockPower")
- local blockBrokenCooldown = valuesFolder:WaitForChild("BlockBrokenCooldown")
- local dodgeDashCooldown = valuesFolder:WaitForChild("DodgeDashCooldown")
- local blockCooldown = valuesFolder:WaitForChild("BlockCooldown")
- local attackCooldown = valuesFolder:WaitForChild("AttackCooldown")
- local isBlocking = valuesFolder:WaitForChild("IsBlocking")
- local maxBlockPower = valuesFolder:WaitForChild("MaxBlockPower")
- local specialCooldown = valuesFolder:WaitForChild("SpecialCooldown")
- local heavyCooldown = valuesFolder:WaitForChild("HeavyCooldown")
- local blockWasBroken = valuesFolder:WaitForChild("BlockWasBroken")
- local canAttack = valuesFolder:WaitForChild("CanAttack")
- local blockRegenTime = valuesFolder:WaitForChild("BlockRegenTime")
- local normalAttackDamage = valuesFolder:WaitForChild("NormalAttackDamage").Value
- local specialAttackDamage = valuesFolder:WaitForChild("SpecialAttackDamage").Value
- local heavyAttackDamage = valuesFolder:WaitForChild("HeavyAttackDamage").Value
- local rightKaliHitbox = script.Parent:WaitForChild("Handle"):WaitForChild("Hitbox")
- local leftKaliHitbox = leftHandKali:WaitForChild("Handle"):WaitForChild("Hitbox")
- local attackIsFired = false
- local heavyIsFired = false
- local specialIsFired = false
- local hitTargets = {}
- local equippedPlayer = nil
- local equippedCharacter = nil
- -- // Helper Functions
- local function getCharacter()
- local parent = script.Parent.Parent
- if parent and parent:FindFirstChild("Humanoid") then
- return parent
- end
- return nil
- end
- local function getPlayerFromCharacter(character)
- return players:GetPlayerFromCharacter(character)
- end
- local function tagHumanoid(humanoid, player)
- if humanoid and player then
- local existing = humanoid:FindFirstChild("creator")
- if existing then existing:Destroy() end
- local tag = Instance.new("ObjectValue")
- tag.Name = "creator"
- tag.Value = player
- tag.Parent = humanoid
- game:GetService("Debris"):AddItem(tag, 2)
- end
- end
- -- // Knockback Utility
- local function applyKnockback(targetHumanoid, distance, attackerHumanoid)
- local rootPart = targetHumanoid.Parent:FindFirstChild("HumanoidRootPart")
- if rootPart then
- local direction = (attackerHumanoid and attackerHumanoid.Parent:FindFirstChild("HumanoidRootPart") and
- (attackerHumanoid.Parent.HumanoidRootPart.CFrame.LookVector)) or rootPart.CFrame.LookVector
- rootPart.Velocity = direction * distance * 10
- end
- if attackerHumanoid then
- local attackerRoot = attackerHumanoid.Parent:FindFirstChild("HumanoidRootPart")
- if attackerRoot then
- attackerRoot.Velocity = attackerRoot.CFrame.LookVector * distance * 5
- end
- end
- end
- -- // Hit Processing
- local function processHit(humanoid)
- if not table.find(hitTargets, humanoid) then
- table.insert(hitTargets, humanoid)
- local character = getCharacter()
- local player = getPlayerFromCharacter(character)
- if player then tagHumanoid(humanoid, player) end
- humanoid:TakeDamage(normalAttackDamage)
- applyKnockback(humanoid, 1, character:FindFirstChild("Humanoid"))
- soundsFolder:WaitForChild("Hit"..math.random(1,2)):Play()
- local weapontool = humanoid.Parent and humanoid.Parent:FindFirstChildOfClass("Tool")
- if weapontool then
- weapontool:WaitForChild("Values"):WaitForChild("BlockPower").Value -= 1
- end
- end
- end
- local function processHitHeavy(humanoid)
- if not table.find(hitTargets, humanoid) then
- table.insert(hitTargets, humanoid)
- local character = getCharacter()
- local player = getPlayerFromCharacter(character)
- if player then tagHumanoid(humanoid, player) end
- humanoid:TakeDamage(heavyAttackDamage)
- applyKnockback(humanoid, 2, character:FindFirstChild("Humanoid"))
- soundsFolder:WaitForChild("Hit"..math.random(1,2)):Play()
- local weapontool = humanoid.Parent and humanoid.Parent:FindFirstChildOfClass("Tool")
- if weapontool then
- weapontool:WaitForChild("Values"):WaitForChild("BlockPower").Value -= 2
- end
- end
- end
- local function processHitSpecial(humanoid)
- if not table.find(hitTargets, humanoid) then
- table.insert(hitTargets, humanoid)
- local character = getCharacter()
- local player = getPlayerFromCharacter(character)
- if player then tagHumanoid(humanoid, player) end
- humanoid:TakeDamage(specialAttackDamage)
- applyKnockback(humanoid, 4.5, character:FindFirstChild("Humanoid"))
- local char = humanoid.Parent
- local weapontool = char and char:FindFirstChildOfClass("Tool")
- local blockField = char and char:FindFirstChild("BlockField")
- if weapontool then
- weapontool:WaitForChild("Values"):WaitForChild("BlockPower").Value = 0
- end
- if blockField then
- blockField:Destroy()
- destroyBlockPlayer:FireClient(players:GetPlayerFromCharacter(char))
- end
- end
- end
- local function onHitboxTouched(hit)
- local character = getCharacter()
- if hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= character then
- local humanoid = hit.Parent:FindFirstChild("Humanoid")
- if humanoid and canAttack.Value then
- if attackIsFired then processHit(humanoid)
- elseif heavyIsFired then processHitHeavy(humanoid)
- elseif specialIsFired then processHitSpecial(humanoid) end
- end
- end
- end
- rightKaliHitbox.Touched:Connect(onHitboxTouched)
- leftKaliHitbox.Touched:Connect(onHitboxTouched)
- local function setupLimbHitbox(limb)
- limb.Touched:Connect(function(hit)
- onHitboxTouched(hit)
- end)
- end
- local function onCharacterRemoving(character)
- if equippedCharacter == character then
- local kaliEquipped = character:FindFirstChild("KaliToolL")
- if kaliEquipped then kaliEquipped:Destroy() end
- local blockField = character:FindFirstChild("BlockField")
- if blockField then blockField:Destroy() end
- equippedCharacter = nil
- equippedPlayer = nil
- end
- end
- -- // Equip
- script.Parent.Equipped:Connect(function()
- local tool = script.Parent
- local character = tool.Parent
- local player = players:GetPlayerFromCharacter(character)
- canAttack.Value = true
- if player and character then
- equippedPlayer = player
- equippedCharacter = character
- player.CharacterRemoving:Connect(onCharacterRemoving)
- local rightArm = character:FindFirstChild("RightArm") or character:FindFirstChild("RightHand")
- local leftArm = character:FindFirstChild("LeftArm") or character:FindFirstChild("LeftHand")
- if rightArm then setupLimbHitbox(rightArm) end
- if leftArm then setupLimbHitbox(leftArm) end
- local oldUnequipped = character:FindFirstChild("KaliAccUnequip")
- if oldUnequipped then oldUnequipped:Destroy() end
- local newKaliLeft = accBank:FindFirstChild("KaliToolL"):Clone()
- newKaliLeft.Name = "KaliToolL"
- newKaliLeft.Parent = character
- tool:SetAttribute("EquippedLeftKaliName", newKaliLeft.Name)
- else
- warn("[Kali Equip] Failed to resolve character or player.")
- end
- end)
- -- // Unequip
- script.Parent.Unequipped:Connect(function()
- canAttack.Value = false
- attackIsFired = false
- hitTargets = {}
- if equippedPlayer and equippedCharacter then
- local kaliEquipped = equippedCharacter:FindFirstChild("KaliToolL")
- if kaliEquipped then kaliEquipped:Destroy() end
- local newUnequipped = accBank:FindFirstChild("KaliAccUnequip"):Clone()
- newUnequipped.Name = "KaliAccUnequip"
- newUnequipped.Parent = equippedCharacter
- else
- warn("[Kali Unequip] Player or character reference missing.")
- end
- equippedPlayer = nil
- equippedCharacter = nil
- end)
- -- // Blocking Events
- beginBlocking.OnServerEvent:Connect(function()
- local character = getCharacter()
- if character and not character:FindFirstChild("BlockField") then
- local blockField = Instance.new("ForceField")
- blockField.Name = "BlockField"
- blockField.Visible = true
- blockField.Parent = character
- end
- isBlocking.Value = true
- end)
- endBlocking.OnServerEvent:Connect(function()
- local character = getCharacter()
- local blockField = character and character:FindFirstChild("BlockField")
- if blockField then blockField:Destroy() end
- isBlocking.Value = false
- end)
- destroyBlockOpponent.OnServerEvent:Connect(function(_, opponent)
- if opponent and opponent:IsA("Player") then
- local character = opponent.Character
- if character then
- local blockField = character:FindFirstChild("BlockField")
- if blockField then blockField:Destroy() end
- local hum = character:FindFirstChild("Humanoid")
- if hum then hum:TakeDamage(normalAttackDamage / 2) end
- end
- end
- end)
- local function resetAttackFlags()
- attackIsFired = false
- heavyIsFired = false
- specialIsFired = false
- end
- dialAttack.OnServerEvent:Connect(function()
- resetAttackFlags()
- attackIsFired = true
- hitTargets = {}
- end)
- dialHeavy.OnServerEvent:Connect(function()
- resetAttackFlags()
- heavyIsFired = true
- hitTargets = {}
- end)
- dialSpecial.OnServerEvent:Connect(function()
- resetAttackFlags()
- specialIsFired = true
- hitTargets = {}
- end)
- -- // Block Regen
- task.spawn(function()
- while task.wait(blockRegenTime.Value) do
- if blockPower.Value < maxBlockPower.Value then
- blockPower.Value = math.min(blockPower.Value + 1, maxBlockPower.Value)
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement