Hello there! My script doesn’t play animation when activated but it prints “endedwhat?” in end of animation event. Here is a script:
local tool = script.Parent
local animations = tool.Animations
local attackAnimation = animations.Attack
local db = false
local eventModule = require(game.ReplicatedStorage.Modules.Events)
tool.Activated:Connect(function()
local damage = tool:GetAttribute('Damage')
local cooldown = tool:GetAttribute('Cooldown')
local char = tool.Parent
local handle = tool.Handle
local hum = char:FindFirstChildWhichIsA('Humanoid')
if not handle then return end
if not hum or hum.Health<=0 then return end
if db then return end
db=true
local animator = hum:FindFirstChildOfClass('Animator')
local attackAnim = hum:LoadAnimation(attackAnimation)
local startedAttack=tick()
attackAnim:Play()
local hitList={}
local touched = handle.Touched:Connect(function(part)
local humanoid = part.Parent:FindFirstChildWhichIsA('Humanoid')
if not humanoid then return end
if table.find(hitList,humanoid) then return end
if game.Players:GetPlayerFromCharacter(humanoid) then
eventModule.DamagePlayer(humanoid.Parent,damage)
else
humanoid:TakeDamage(damage)
end
table.insert(hitList,humanoid)
end)
local attackEndedEvent
attackEndedEvent = attackAnim.Stopped:Connect(function()
touched:Disconnect()
attackEndedEvent:Disconnect()
print('endedwhat?')
end)
wait(startedAttack+cooldown-tick())
--repeat wait() until startedAttack+cooldown<tick()
db=false
end)
Do you made sure that the animation is published to Roblox and you are the one who published the animation? It doesn’t works if you get an animation from Toolbox for example and just use the AnimationId of this one, you have to publish it to Roblox first. To do this firstly right click the Animation and then click Save to Roblox, after that you can copy the Id of the Animation.
I think you dont have to load the animation everytime when the tool is activated. Try putting the Load animation function before the tool.activated one.
tool.Parent.Changed:Connect(function()
local parent=tool.Parent
local hum = parent:FindFirstChildWhichIsA('Humanoid')
if not hum then return end
attackAnim = hum:LoadAnimation(attackAnimation)
attackAnim:Play()
end)
Because i want to make this tool droppable. But it doesnt work too. Also function animation.Ended fires in about 2 seconds what’s the length of animation.
local tool = script.Parent
local animations = tool.Animations
local attackAnimation = animations.Attack
local db = false
local eventModule = require(game.ReplicatedStorage.Modules.Events)
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local attackAnim = hum:LoadAnimation(attackAnimation)
tool.Activated:Connect(function()
print(char,hum)
if not hum or hum.Health<=0 then return end
local startedAttack=tick()
attackAnim:Play()
print('played')
end)
But it doesn’t seem to work.
But if i unequip tool before playing animation,animation plays.