#can someone explain me how to script a animation to play on click i made a script but it wont work

1 messages · Page 1 of 1 (latest)

open sleet
#

local tool = script.Parent
local animation = tool:FindFirstChild("swing") -- Make sure this exists and has AnimationId set!

tool.Activated:Connect(function()
local character = tool.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid and animation then
print(character.Name .. ' swinged his sword')
local track = humanoid:LoadAnimation(animation)
track:Play()
else
warn('No humanoid or animation found!')
end
end)

open sleet
#

ok but actualy the script work but when i hold tool it doesn't

#

i think it is just anchored let me check

slim ice
#

we cant help otherwise

open sleet
#

ok

#

here and handle isn't anchored

#

need any proprities ?

#

still here @slim ice and @lusty quartz ?

slim ice
#

local tool = script.Parent
local animation = tool:FindFirstChild("swing")

tool.Activated:Connect(function()
local character = tool.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animator = humanoid and humanoid:FindFirstChildOfClass("Animator")
if humanoid and animator and animation then
print(character.Name .. " swinged his sword")
local track = animator:LoadAnimation(animation)
track:Play()
else
warn("No humanoid or animation found!")
end
end)

#

wait

#

idk actually

open sleet
#

you think it is the tool because when i dont hold it does the animation

slim ice
#

maybe the priority is too low

#

local tool = script.Parent
local animation = tool:FindFirstChild("swing")

tool.Activated:Connect(function()
local character = tool.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animator = humanoid and humanoid:FindFirstChildOfClass("Animator")
if humanoid and animator and animation then
print(character.Name .. " swinged his sword")
local track = animator:LoadAnimation(animation)
track.Priority = Enum.AnimationPriority.Action4
track:Play()
else
warn("No humanoid or animation found!")
end
end)

#

this could work

open sleet
#

wow so youre a black magic wizzard

#

but what did you change i dont just paste code i try to learn

slim ice
open sleet
#

yes

slim ice
#

basically all i did was change the animation priority and add animator

#

changing the priority

#

track.Priority = Enum.AnimationPriority.Action4

#

action 4 is the "highest" priority, therefore runs over other animations

#

and animator is the newer thing because im pretty sure loadanimation is deprecated

open sleet
#

ooh ok smart because holding the tool count as animation right?

slim ice
#

anything else i can help with?

open sleet