I’m trying to make an attack animation play whenever I click with a tool but the animation won’t play. The script is: local remote = script.Parent:WaitForChild(“Handler”) – we store the remote event into a variable
remote.OnServerEvent:Connect(function(Player, Value) – once the remote was firesevered
local character = script.Parent.Parent.Parent – the player’s character
if Value == “Equipped” then – if the string argument wants us to equip the sword then…
print(“equipped”)
local lookForAnimation = character:FindFirstChild("EquippedAnimation") -- we look for something called "EquippedAnimation" inside the player's character, that will be the equipped animation
if lookForAnimation then -- if that was found then...
lookForAnimation:Destroy() --we destroy it
end
local animation = Instance.new("Animation", character) --we create a new animation inside of the player's character
animation.Name = "EquippedAnimation" -- we call it "EquippedAnimation"
animation.AnimationId = "rbxassetid://7493773366" -- we change its animation id to the equipped animation's id, VERY IMPORTANT YOU NEED TO CREATE UR OWN ANIMATION AND EXPORT IT TO MAKE IT WORK
local loader = character:WaitForChild("Humanoid"):LoadAnimation(animation) -- we load that animation per humanoid
loader:Play() -- we play that animation loader
elseif Value == "Unequipped" then
print("unequipped")
local animationTracks = character:WaitForChild("Humanoid"):GetPlayingAnimationTracks()
for _, v in pairs(animationTracks)do
if v.Name == "EquippedAnimation" then
v:Stop()
end
end
elseif Value == "Attack" then -- if the string argument wants us to attack then...
print("attack")
local avaibleAttackAnimations = {7493763859,7493773366} -- a table which contains multiple attack animation ids
local animation = Instance.new("Animation", character) --we create a new animation inside of the player's character
animation.Name = "AttackAnimation" -- we call it "EquippedAnimation"
animation.AnimationId = "rbxassetid://"..tostring(avaibleAttackAnimations[math.random(1, #avaibleAttackAnimations)]) -- we choose an animation id randomly from that avaiable animations table, VERY IMPORTANT YOU NEED TO CREATE UR OWN ANIMATION AND EXPORT IT TO MAKE IT WORK
local loader = character:WaitForChild("Humanoid"):LoadAnimation(animation) -- we load that animation per humanoid
loader:Play() -- we play that animation loader
script.Parent.Parent.Base.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= Player.Name and character:FindFirstChild("AttackAnimation") then -- we check if the thing we hit is a npc or a player and does not have the same name as the player has
if not hit.Parent:FindFirstChild("HitFolder") then
local f = Instance.new("Folder", hit.Parent)
f.Name = "HitFolder"
end
if not hit.Parent:FindFirstChild("HitFolder"):FindFirstChild(Player.Name) then
local x = Instance.new("IntValue", hit.Parent:FindFirstChild("HitFolder"))
x.Name = Player.Name
game.Debris:AddItem(x, 2)
local meleeMulti = character:WaitForChild("Melee Multi")
local meleeBoost = meleeMulti.Value
hit.Parent.Humanoid:TakeDamage(250 + meleeBoost) -- we make the thing we hit take 10 damage, you can change that 10 to whatever you want
end
end
end)
wait(1)
loader:Stop()
animation:Destroy()
end
end)