The tool (Server Script)
local Cooldown = false
local onGoing = false
local SS = game:GetService("ServerStorage")
local attacks = SS.Characters.Voidwalker
local HollowEarthModel = attacks.HollowEarth
local debris = game:GetService("Debris")
local UIS = game:GetService("UserInputService")
local players = game:GetService("Players")
local tool = script.Parent
local name = tool.Name
local CD = 0.1
local handle = tool.Handle
local idle = tool.Idle
local dash = tool.Dash
local event1 = tool.DashEvent
local event2 = tool.MeleeEvent
local event3 = tool.CancelMelee
local event4 = tool.HollowEarthEvent
local thread = nil
local globalCooldown = nil
local idleAnim = nil
local loadedDash = nil
local slash = nil
local slash2 = nil
local slash3 = nil
local slash4 = nil
local slash5 = nil
local hollowf = nil
local hollowearthanim = nil
local teleport = nil
local actualslash = nil
local trueplayer = nil
local animationdetectorthread = coroutine.create(function()
while true do
task.wait(1)
local currentracks = trueplayer:WaitForChild("Humanoid"):GetPlayingAnimationTracks()
print(currentracks)
end
end)
thread = task.spawn(function()
repeat
task.wait()
until trueplayer ~= nil
if trueplayer then
local animator = trueplayer:FindFirstChild("Humanoid").Animator
idleAnim = animator:LoadAnimation(tool.Idle)
slash = animator:LoadAnimation(tool.Slash1)
slash2 = animator:LoadAnimation(tool.Slash2)
loadedDash = animator:LoadAnimation(tool.Dash)
hollowearthanim = animator:LoadAnimation(tool["Hollow Earth"])
coroutine.resume(animationdetectorthread)
end
end)
local curAnim = nil
local slash1 = tool.Slash1
local slash2 = tool.Slash2
local hollowearth = tool["Hollow Earth"]
tool.Equipped:Connect(function()
tool.LocalScript.Enabled = true
local player = script.Parent.Parent
if trueplayer == nil then
trueplayer = player
end
local animator = player:FindFirstChild("Humanoid").Animator
repeat
task.wait()
until idleAnim ~= nil
task.cancel(thread)
curAnim = idleAnim
curAnim:Play()
tool.Unequipped:Wait()
if curAnim ~= nil then
curAnim:Stop()
trueplayer:FindFirstChild("Humanoid"):FindFirstChild("AntiSlow").Enabled = true
trueplayer:FindFirstChild("Humanoid").WalkSpeed = trueplayer:FindFirstChild("Humanoid"):FindFirstChild("OgWalkspeed").Value
trueplayer.Animate.Enabled = true
curAnim = nil
end
tool.LocalScript.Enabled = false
if globalCooldown ~= nil then
globalCooldown:Destroy()
end
Cooldown = false
end)
event1.OnServerEvent:Connect(function(player, keyCode)
if Cooldown == false and trueplayer:FindFirstChild("GLOBALCOOLDOWN") == nil then
Cooldown = true
local animate = trueplayer:FindFirstChild("Animate")
animate.Enabled = false
local boolValue = Instance.new("BoolValue", trueplayer)
boolValue.Name = "GLOBALCOOLDOWN"
globalCooldown = boolValue
curAnim = loadedDash
curAnim:Play()
local linearForce = Instance.new("BodyVelocity", trueplayer.HumanoidRootPart)
linearForce.Parent = trueplayer.HumanoidRootPart
linearForce.MaxForce = Vector3.new(1,0,1)*100000
local lookVector = trueplayer:GetPivot().LookVector
linearForce.Velocity = lookVector*2500
task.wait(0.25)
linearForce:Destroy()
trueplayer.HumanoidRootPart.Velocity = Vector3.new(0,25,0)
if curAnim ~= nil then
curAnim:Stop()
curAnim = nil
curAnim = idleAnim
end
animate.Enabled = true
Cooldown = false
boolValue:Destroy()
end
end)
For context, I’m trying to make a melee weapon that uses animations to attack. When using keybind moves or clicking and holding (a problem that was never resolved that I still do not know how to debug, see post here if you are interested I need help debugging a tool that attacks multiple times but then cancels if the player releases their mouse early when they hold click the tool), the animations work as intended. The attacks appear, the animations load, and they play. However, there is one problem. The AnimationTracks. I do not know how to make it so that only one animation plays and does not play ontop of another, creating excess AnimationTracks that eventually breaks the weapon. I’ve already tried a solution, that being preloading the animations.
thread = task.spawn(function()
repeat
task.wait()
until trueplayer ~= nil
if trueplayer then
local animator = trueplayer:FindFirstChild("Humanoid").Animator
idleAnim = animator:LoadAnimation(tool.Idle)
slash = animator:LoadAnimation(tool.Slash1)
slash2 = animator:LoadAnimation(tool.Slash2)
loadedDash = animator:LoadAnimation(tool.Dash)
hollowearthanim = animator:LoadAnimation(tool["Hollow Earth"])
coroutine.resume(animationdetectorthread)
end
end)
However, even then preloading of animations onto the player’s Animator doesn’t work. I tried preloading the animations and the amount of AnimationTracks still go up nonstop, almost as if its duplicating. I don’t know how exactly I can prevent this. Loading the animations separately doesn’t work. I haven’t even figured out what I can do to prevent this.
Thus, I’m asking for help. Figuring out a way to prevent excess AnimationTracks has been really annoying to do and I don’t know what I can do anymore. I use any of the moves multiple times and when the :GetPlayingAnimationTracks() prints out, there are over 30 results, almost as if another one is being created after the already loaded animation. I don’t know how I can fix this problem.
If anyone would like to help, please do! I haven’t been able to figure out how I can solve this problem.