Hello guys,
So currently, i have been working to make a weapon that plays multiple animations in a row.
At first, everything seem to be fine, but then this problem occur:
Here's the code
local RS = game:GetService("ReplicatedStorage")
local Player = game:GetService("Players")
local uis = game:GetService("UserInputService")
local char = Player.LocalPlayer.Character or Player.LocalPlayer.CharacterAdded:Wait()
local clientCast = require(RS.ClientCast)
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local tool = script.Parent
local isequiped = false
local combo = 0
local WPDT = require(RS.GameDataStorage.Weapons)
local clicked = false
--other attacks
local function leghitbox (leg)
local cloneLeg = game.Workspace.Body["Left Leg"]:Clone()
cloneLeg.Anchored = false
cloneLeg.CanCollide = false
cloneLeg.Name = "cloneLeg"
cloneLeg.Transparency = 1
local legHit = clientCast.new(cloneLeg, RaycastParams.new())
local weld = Instance.new("Weld")
weld.Parent = leg
weld.Part0 = leg
weld.Part1 = cloneLeg
cloneLeg.CFrame = leg.CFrame
cloneLeg.Parent = leg
legHit:Start()
end
local function stopLeghitbox (leg)
if leg.cloneLeg and leg.Weld then
leg.cloneLeg:Destroy()
leg.Weld:Destroy()
else
return
end
end
--animations plays
local walktrack
local idletrack
print(animator)
--tool unequiped
local function PAttack (SUani, ATani, ELani)
local track
track = animator:LoadAnimation(SUani)
track.Looped = false
track:Play()
track.Stopped:wait()
track:Stop(0)
track = animator:LoadAnimation(ATani)
track.Looped = false
track:Play()
track.Stopped:wait()
track:Stop(0)
track = animator:LoadAnimation(ELani)
track.Looped = false
track:Play()
track.Stopped:wait()
track:Stop(0)
end
--tool equiped
tool.Equipped:Connect(function()
--arms
local leftArm = char:FindFirstChild("Left Arm")
local rightArm = char:FindFirstChild("Right Arm")
--clientcast
local rightHitbox = clientCast.new(tool.Larm.Union, RaycastParams.new()) --i messed up the order lmao
local leftHitbox = clientCast.new(tool.Rarm.Union, RaycastParams.new()) -- dont worry it will be fine
leftHitbox:Stop()
rightHitbox:Stop()
uis.InputBegan:Connect(function(key,gpe)
if gpe then return end
if key.UserInputType == Enum.UserInputType.MouseButton1 and clicked == false then
clicked = true
--combo
combo = combo % 3 + 1
--get attacks
local attacks = WPDT:GetWeaponAttacks("Iron Gloves")
--attacks animation
local SUani = Instance.new("Animation")
local ATani = Instance.new("Animation")
local ELani = Instance.new("Animation")
SUani.Parent = RS
ATani.Parent = RS
ELani.Parent = RS
SUani.AnimationId = "rbxassetid://"..tostring(attacks[combo].Startup)
ATani.AnimationId = "rbxassetid://"..tostring(attacks[combo].Attacking)
ELani.AnimationId = "rbxassetid://"..tostring(attacks[combo].Endlag)
print(combo)
local leg = char:FindFirstChild("Right Leg")
local hitbox
if combo == 1 or combo == 3 then
hitbox = leftHitbox
else
hitbox = rightHitbox
end
-- local attackTime = 0
-- local attackTimeTrack = animator:LoadAnimation(SUani)
-- attackTime += attackTimeTrack.length
-- local attackTimeTrack = animator:LoadAnimation(ATani)
-- attackTime += attackTimeTrack.length
-- local attackTimeTrack = animator:LoadAnimation(ELani)
-- attackTime += attackTimeTrack.length
PAttack(SUani,ATani,ELani,hitbox)
rightHitbox:Stop()
leftHitbox:Stop()
clicked = false
SUani:Destroy()
ATani:Destroy()
ELani:Destroy()
end
end)
end)```
I tried to look for solutions all around the dev forum but all of them gives the same result. So I posted one myself to find it.
Any help is appreciated, thank you!