I’m trying to find a way to run one sword after the other to replicate the mechanism of Become OP where when a player contains multiple sword it goes one after the other like in this video I’m going to show you
So this is the code of my SwingSword for the moment I struggle to manage multiple sword and only 1 sword works at the moment so when I have another sword that I want to run immediately after the first sword has triggered I’d like to start another sword
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Star = require(ReplicatedStorage:WaitForChild("ClientScripts"):WaitForChild("Star"))
local SelectCard = Remotes:WaitForChild("SelectCard")
local AttributeAbility = Remotes:WaitForChild("AttributeAbility")
local player = Players.LocalPlayer
local Character = player.Character
local mouse = player:GetMouse()
local swords = {}
local function getAllSwords()
for _, item in pairs(Character:GetChildren()) do
if item.Name:match("^Warrior Sword") then
table.insert(swords, item)
end
end
return swords
end
swords = getAllSwords()
local healthUpdateEvent = ReplicatedStorage:WaitForChild("HealthUpdateEvent")
local WeaponController = require(ReplicatedStorage:WaitForChild("ClientScripts"):WaitForChild("WeaponController"))
local radius = 5
local forwardOffset = 3
local stabDistance = 5
local stabTime = 3
local heightOffset = 2
local elapsedTime = 0
local isStabbing = false
local isStabbingEnded = false
local currentPosition = nil
local stabFinalOffset = nil
local stabFinalDirection = nil
local disappearSword = false
local forceStop = false
local NumberSword = 0
-------------------- HAMMER ABILITY -----------------------------
local HammerAttackSpeed = script:GetAttribute("HammerAttackSpeed")
local HammerAttackSpeedLevel = script:GetAttribute("HammerAttackSpeedLevel")
local HammerAttack = script:GetAttribute("HammerAttack")
local HammerAttackLevel = script:GetAttribute("HammerAttackLevel")
local HammerAttackcritical = script:GetAttribute("HammerAttackcritical")
local HammerAttackcriticalLevel = script:GetAttribute("HammerAttackcriticalLevel")
local HammerAttackcooldown = script:GetAttribute("HammerAttackCooldown")
local HammerAttackcooldownLevel = script:GetAttribute("HammerAttackCooldownLevel")
local HammerAttackpoisonLevel = script:GetAttribute("HammerAttackpoisonLevel")
local HammerAttackpoison = script:GetAttribute("HammerAttackpoison")
local HammerAttackAdd = script:GetAttribute("HammerAttackAdd")
local HammerAttackAddLevel = script:GetAttribute("HammerAttackAddLevel")
local HammerAttackScale = script:GetAttribute("HammerAttackscale")
local HammerAttackScaleLevel = script:GetAttribute("HammerAttackscaleLevel")
-------------------- SWORD ABILITY -----------------------------
local SwordAttackSpeed = script:GetAttribute("SwordAttackSpeed")
local SwordAttackSpeedLevel = script:GetAttribute("SwordAttackSpeedLevel")
local SwordAttack = script:GetAttribute("SwordAttack")
local SwordAttackLevel = script:GetAttribute("SwordAttackLevel")
local SwordAttackcritical = script:GetAttribute("SwordAttackcritical")
local SwordAttackcriticalLevel = script:GetAttribute("SwordAttackcriticalLevel")
local SwordAttackcooldown = script:GetAttribute("SwordAttackCooldown")
local SwordAttackcooldownLevel = script:GetAttribute("SwordAttackCooldownLevel")
local SwordAttackpoisonLevel = script:GetAttribute("SwordAttackpoisonLevel")
local SwordAttackpoison = script:GetAttribute("SwordAttackpoison")
local SwordAttackAdd = script:GetAttribute("SwordAttackAdd")
local SwordAttackAddLevel = script:GetAttribute("SwordAttackAddLevel")
local SwordAttackScale = script:GetAttribute("SwordAttackscale")
local SwordAttackScaleLevel = script:GetAttribute("SwordAttackscaleLevel")
-------------------- ANY ABILITY -----------------------------
local WalkSpeed = script:GetAttribute("WalkSpeed")
local WalkSpeedLevel = script:GetAttribute("WalkSpeedLevel")
local Health = script:GetAttribute("Health")
local HealthLevel = script:GetAttribute("HealthLevel")
local Expboost = script:GetAttribute("Expboost")
local ExpboostLevel = script:GetAttribute("ExpboostLevel")
local Fortuneboost = script:GetAttribute("Fortuneboost")
local FortuneboostLevel = script:GetAttribute("FortuneboostLevel")
local debounceMonsters = {}
local function SmoothCurve(t)
return 1 - math.pow(1 - t, 3)
end
local function FindPoint(mouseRay, planeY)
local direction = mouseRay.Direction
local origin = mouseRay.Origin
if direction.Y == 0 then return nil end
local distance = (planeY - origin.Y) / direction.Y
return origin + direction * distance
end
local function UpdateSwordPosition(deltaTime, swordModel)
if not player:FindFirstChild("IsPlaying") or not player.IsPlaying.Value then return end
if not Character or not Character.PrimaryPart then return end
local root = Character.PrimaryPart.Position
local head = Character:FindFirstChild("Head")
if not head then return end
local targetPosition = FindPoint(mouse.UnitRay, head.Position.Y)
if not targetPosition then return end
local horizontalTarget = Vector3.new(targetPosition.X, root.Y, targetPosition.Z)
local direction = (horizontalTarget - root).unit
local invisibleFillingPart = swordModel:WaitForChild("invisible filling part")
if not invisibleFillingPart then
warn("SHARP part is missing in the sword model!")
return
end
if isStabbing and not isStabbingEnded then
if elapsedTime == 0 then
stabFinalDirection = direction
end
disappearSword = false
elapsedTime += deltaTime * SwordAttackSpeed
local progress = math.clamp(elapsedTime / stabTime, 0, 0.4)
local easedProgress = SmoothCurve(progress)
if progress >= 0.4 then
stabFinalOffset = swordModel.PrimaryPart.Position - root
isStabbing = false
isStabbingEnded = true
elapsedTime = 0
end
local swordPosition = root + stabFinalDirection * (radius + forwardOffset + easedProgress * stabDistance) + Vector3.new(0, heightOffset, 0)
currentPosition = swordPosition
swordModel:SetPrimaryPartCFrame(
CFrame.lookAt(swordPosition, swordPosition + stabFinalDirection)
* CFrame.Angles(math.rad(90), math.rad(90), math.rad(180))
)
for _, part in ipairs(invisibleFillingPart:GetTouchingParts()) do
if part.Name ~= "OtherGrip" then
if not debounceMonsters[part.Parent] then
debounceMonsters[part.Parent] = true
healthUpdateEvent:FireServer(SwordAttack, part.Parent, script:GetAttribute("ContainPoison"))
task.wait(1)
debounceMonsters[part.Parent] = false
end
end
end
elseif not isStabbing and isStabbingEnded then
if stabFinalOffset and stabFinalDirection then
elapsedTime += deltaTime * SwordAttackSpeed
local progress = math.clamp(0.4 + (elapsedTime / stabTime), 0, 1)
local easedProgress = SmoothCurve(progress)
if progress >= 0.4 and not disappearSword then
disappearSword = true
WeaponController.Visible(player, swordModel, false)
end
local swordPosition = root + stabFinalDirection * (radius + forwardOffset + easedProgress * stabDistance) + Vector3.new(0, heightOffset, 0)
currentPosition = swordPosition
swordModel:SetPrimaryPartCFrame(
CFrame.lookAt(swordPosition, swordPosition + stabFinalDirection)
* CFrame.Angles(math.rad(90), math.rad(90), math.rad(180))
)
end
end
print("BOTH SWORD HAS FINISHED ANIMATION")
end
task.spawn(function()
while true do
task.wait(SwordAttackcooldown)
swords = getAllSwords()
for _, swordModel in pairs(swords) do
WeaponController.Visible(player, swordModel, true)
end
isStabbing = true
isStabbingEnded = false
elapsedTime = 0
forceStop = false
end
end)
AttributeAbility.Event:Connect(function(abilityName, weapon)
if weapon == "Sword" then
if abilityName == "SwordAttackSpeed" then
if SwordAttackSpeed > 0.1 then
SwordAttackSpeed -= (SwordAttackSpeed * 0.1)
end
SwordAttackSpeedLevel += 1
script:SetAttribute("SwordAttackSpeed", SwordAttackSpeed)
script:SetAttribute("SwordAttackSpeedLevel", SwordAttackSpeedLevel)
elseif abilityName == "SwordAttack" then
SwordAttack += 1
SwordAttackLevel += 1
script:SetAttribute("SwordAttack", SwordAttack)
script:SetAttribute("SwordAttackLevel", SwordAttackLevel)
elseif abilityName == "SwordAttackcritical" then
SwordAttackcritical += 0.1
SwordAttackcriticalLevel += 1
SwordAttack += SwordAttackcritical
script:SetAttribute("SwordAttack", SwordAttack)
script:SetAttribute("SwordAttackcritical", SwordAttackcritical)
script:SetAttribute("SwordAttackcriticalLevel", SwordAttackcriticalLevel)
elseif abilityName == "SwordAttackCooldown" then
if SwordAttackcooldown > 0.1 then
SwordAttackcooldown -= 0.1
end
SwordAttackcooldownLevel += 1
script:SetAttribute("SwordAttackCooldown", SwordAttackcooldown)
script:SetAttribute("SwordAttackCooldownLevel", SwordAttackcooldownLevel)
elseif abilityName == "SwordAttackpoison" then
SwordAttackpoison += 1
SwordAttackpoisonLevel += 1
script:SetAttribute("SwordAttackpoison", SwordAttackpoison)
script:SetAttribute("SwordAttackpoisonLevel", SwordAttackpoisonLevel)
script:SetAttribute("ContainPoison", true)
elseif abilityName == "SwordAttackAdd" then
SwordAttackAdd += 1
SwordAttackAddLevel += 1
swords = getAllSwords()
local newSword = swords[SwordAttackAdd - 1]:Clone()
newSword.Name = "Warrior Sword " .. SwordAttackAdd
table.insert(swords, newSword)
script:SetAttribute("SwordAttackAdd", SwordAttackAdd)
script:SetAttribute("SwordAttackAddLevel", SwordAttackAddLevel)
elseif abilityName == "SwordAttackscale" then
swords = getAllSwords()
SwordAttackScale += (SwordAttackScale * 0.1)
SwordAttackScaleLevel += 1
for index, swordModel in pairs(swords) do
swordModel:ScaleTo(SwordAttackScale)
end
script:SetAttribute("SwordAttackscale", SwordAttackScale)
script:SetAttribute("SwordAttackscaleLevel", SwordAttackScaleLevel)
elseif abilityName == "Regeneration" then
coroutine.wrap(function()
while true do
Remotes:WaitForChild("ChangeHealth"):FireServer(1)
wait(4)
end
end)()
elseif abilityName == "Expboost" then
Expboost += (Expboost * 0.1)
Remotes:WaitForChild("BoostExp"):InvokeServer(Expboost)
end
elseif weapon == "Hammer" then
if abilityName == "HammerAttackSpeed" then
if HammerAttackSpeed > 0.1 then
HammerAttackSpeed -= (HammerAttackSpeed * 0.1)
end
HammerAttackSpeedLevel += 1
script:SetAttribute("HammerAttackSpeed", HammerAttackSpeed)
script:SetAttribute("HammerAttackSpeedLevel", HammerAttackSpeedLevel)
elseif abilityName == "HammerAttack" then
HammerAttack += 1
HammerAttackLevel += 1
script:SetAttribute("HammerAttack", HammerAttack)
script:SetAttribute("HammerAttackLevel", HammerAttackLevel)
elseif abilityName == "HammerAttackcritical" then
HammerAttackcritical += 0.1
HammerAttackcriticalLevel += 1
HammerAttack += HammerAttackcritical
script:SetAttribute("HammerAttack", HammerAttack)
script:SetAttribute("HammerAttackcritical", HammerAttackcritical)
script:SetAttribute("HammerAttackcriticalLevel", HammerAttackcriticalLevel)
elseif abilityName == "HammerAttackCooldown" then
if HammerAttackcooldown > 0.1 then
HammerAttackcooldown -= 0.1
end
HammerAttackcooldownLevel += 1
script:SetAttribute("HammerAttackCooldown", HammerAttackcooldown)
script:SetAttribute("HammerAttackCooldownLevel", HammerAttackcooldownLevel)
elseif abilityName == "HammerAttackpoison" then
HammerAttackpoison += 1
HammerAttackpoisonLevel += 1
script:SetAttribute("HammerAttackpoison", HammerAttackpoison)
script:SetAttribute("HammerAttackpoisonLevel", HammerAttackpoisonLevel)
script:SetAttribute("ContainPoison", true)
elseif abilityName == "HammerAttackAdd" then
HammerAttackAdd += 1
HammerAttackAddLevel += 1
script:SetAttribute("HammerAttackAdd", HammerAttackAdd)
script:SetAttribute("HammerAttackAddLevel", HammerAttackAddLevel)
elseif abilityName == "HammerAttackscale" then
HammerAttackScale += (HammerAttackScale * 0.1)
HammerAttackScaleLevel += 1
script:SetAttribute("HammerAttackscale", HammerAttackScale)
script:SetAttribute("HammerAttackscaleLevel", HammerAttackScaleLevel)
end
elseif weapon == "AnyWeapon" then
if abilityName == "WalkSpeed" then
Character.Humanoid.WalkSpeed += (Character.Humanoid.WalkSpeed * 0.1)
WalkSpeed += (Character.Humanoid.WalkSpeed * 0.1)
WalkSpeedLevel += 1
script:SetAttribute("WalkSpeed", WalkSpeed)
script:SetAttribute("WalkSpeedLevel", WalkSpeedLevel)
elseif abilityName == "Health" then
Health += 5
HealthLevel += 1
script:SetAttribute("Health", Health)
script:SetAttribute("HealthLevel", HealthLevel)
Remotes:WaitForChild("ChangeHealth"):FireServer(Health)
elseif abilityName == "Expboost" then
Expboost += (Expboost * 0.1)
ExpboostLevel += 1
script:SetAttribute("Expboost", Expboost)
script:SetAttribute("ExpboostLevel", ExpboostLevel)
Remotes:WaitForChild("BoostExp"):InvokeServer(Expboost)
elseif abilityName == "Fortuneboost" then
Fortuneboost += (Fortuneboost * 0.1)
FortuneboostLevel += 1
print("FORTUNE BOOST IS : ", Fortuneboost)
print("FORTUNE BOOST LEVEL IS : ", FortuneboostLevel)
script:SetAttribute("Fortuneboost", Fortuneboost)
script:SetAttribute("FortuneboostLevel", FortuneboostLevel)
end
end
end)
RunService.RenderStepped:Connect(function(deltaTime)
print("SWORD COUNT IS : ", #swords)
for i = 1, #swords do
UpdateSwordPosition(deltaTime, swords[1])
end
end)