I’m making a game that involves a staff. This script is supposed to play an animation, but for some reason it won’t work. Here is the script.
local hitbox = script.Parent.Hitbox
local staff = script.Parent
-- ignore this function - it works fine
function onTouch(part)
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
-- if player exsists and can damage is true then deal damage
if player then
character.Humanoid:TakeDamage(21)
end
end
staff.Hitbox.Touched:Connect(onTouch)
-- this is the one that doesn't play the animation
function yeetTheNoob()
local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing):LoadAnimation()
attack.AnimationId = 6527600949
attack:Play()
end
script.Parent:Activate(yeetTheNoob)
There are no errors in the output.
Hope you all are enjoying your day,
–@Mithrandir6440
script.StaffSwing.AnimationId = "6527600949" -- i dont remember if this is an integer or a string.
local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing) -- make sure staffswing is animation instance.
attack:Play()
‘’’'lua
local hitbox = script.Parent.Hitbox
local staff = script.Parent
– ignore this function - it works fine
function onTouch(part)
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
-- if player exsists and can damage is true then deal damage
if player then
character.Humanoid:TakeDamage(21)
end
end
staff.Hitbox.Touched:Connect(onTouch)
– this is the one that doesn’t play the animation
function yeetTheNoob()
print('AA')
local staffSwing = script.StaffSwing
staffSwing.AnimationId = "6527600949"
local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing)
attack:Play()
I think you need to make “StaffSwing” a normal animation for it to have an AnimationId.
Either that or you need to submit the animation to Roblox to have a usable Id (while still using a normal animation) but I may be wrong on that.
If you already have an AnimationId for an animation, I think you just need to change “StaffWing” into an animation instead of a KeyFrameSequence and try to set the Id to that, same script, different type of thing.
try inserting an animation into the staff (make sure to name it StaffSwing), looks like this,
then put the id in the AnimationId in the properties of the animation, then instead of writing this
change it to
local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing) --take away the extra load animation
attack:Play()
This will work for now, until they remove the :LoadAnimation
Well, I would say that having it as an actual object in the explorer with the variable already inside is easier, and it is a method that I use that works. Your method probably works too, though I have never tried it. I am just giving @CJ_Nelson01 different options.
local hitbox = script.Parent.Hitbox
local staff = script.Parent
-- ignore this function - it works fine
function onTouch(part)
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
-- if player exsists and can damage is true then deal damage
if player then
character.Humanoid:TakeDamage(21)
end
end
staff.Hitbox.Touched:Connect(onTouch)
-- this is the one that doesn't play the animation
function yeetTheNoob()
local attack = staff.Parent.Humanoid:LoadAnimation(script.StaffSwing):LoadAnimation()
attack.AnimationId = "rbxassetid://6527600949"
attack:Play()
end
script.Parent:Activate(yeetTheNoob)
None of these suggestions work. I have removed keyframes, looked on the official website, and tried everyone else’s suggestions. I even tried this script that I created by myself.
‘’‘’
function yeetTheNoob()
local animator = script.Parent.Parent.Humanoid:WaitForChild('Animator')
local staffSwing = Instance.new('Animation')
staffSwing.AnimationId = 'rbxassetid://6527600949'
local staffSwingTrack = animator:LoadAnimation(staffSwing)
staffSwingTrack:Play()
keyframes don’t belong in an animation, it should require the id, put the id in an animation object and copy the link from that and paste it into the script.
let me load a old script for a sword i made and see how i am able to load an animation so i can put this up further.
Many thanks to all who worked on this, but this issue has finally been solved. The issue was with the animation being incorrectly formatted and the animation priority being incorrect.
Hope you all are having a good day,
–@Mithrandir6440