I am trying to get my animation to play when equipping my sword. I have tried a few different solutions including the one in the script below. Can anyone show me how to make the animation play.
Thanks
local animations = {"7962822434"; "7962845607"} -- Add your animation ID's here for the slashing of the sword. These will be chosen randomly every time the sword is activated.
local tool = script.Parent
local enabled = true
local char
local coolDown = .8 -- cooldown for sword activation in seconds
local swing = script.Parent.Handle.swing
local animation = script.Parent:FindFirstChild("Animation")
tool.Activated:connect(function()
animation:Play()
if enabled then
enabled = false
local char = tool.Parent
local random = animations[math.random(1,#animations)]
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id="..random
local track = char.Humanoid:LoadAnimation(anim)
track:Play()
swing:Play()
local dmg = script.Damage:Clone()
dmg.Parent = tool.Handle
dmg.Disabled = false
wait(coolDown)
enabled = true
if dmg then
dmg:Destroy()
end
end
end)
local tool = script.Parent -- define tool path
local animation = script.Parent.Animation -- define the animation path
tool.Equipped:Connect(function()
local hum = script.Parent.Parent.Humanoid -- Only defined if the tool is in starterpack
local track = hum:LoadAnimation(animation)
track:Play()
end)
Try this. Should load animation on equipped.Make sure to define the 2 variables above.
local animations = {"7962822434"; "7962845607"} -- Add your animation ID's here for the slashing of the sword. These will be chosen randomly every time the sword is activated.
local tool = script.Parent
local enabled = true
local char
local coolDown = .8 -- cooldown for sword activation in seconds
local swing = script.Parent.Handle.swing
local animation = script.Parent:FindFirstChild("Animation")
tool.Activated:connect(function()
local player = game.Players:GetPlayerFromCharacter(script.Parent) -- Add parent's if the script is deeper inside of the tool.
player.Character.Humanoid:LoadAnimation(animation):Play()
if enabled then
enabled = false
local char = tool.Parent
local random = animations[math.random(1,#animations)]
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id="..random
local track = char.Humanoid:LoadAnimation(anim)
track:Play()
swing:Play()
local dmg = script.Damage:Clone()
dmg.Parent = tool.Handle
dmg.Disabled = false
wait(coolDown)
enabled = true
if dmg then
dmg:Destroy()
end
end
end)