I’m trying to make an NPC pick up an axe. Right now I have it so there is two axes, one is invisible and connected to the left hand, and the other is visible and on a table connected to the humanoid root part. What I want it to do is when the hand is on the axe, it will swap which one is transparent and which one isn’t to make it look like it’s being picked up. My problem is that the axe is being ‘picked up’ and ‘placed down’ before the hand is even near the axe on the table. I’ve searched this up and all I could find was that local scripts would be more reliable, but the animation won’t even play in a local script for whatever reason and I would rather it be on the server if possible anyways. (Also if it helps, the animation is 120 fps but slowed down to 0.01 so it could last longer)
I’m a little confused as to which axe is which, but have you tried just reversing the transparencies for all of them? If it does the opposite of what you’re expecting, then switch your values. Unless this is just a timing issue, in which case yes, local scripts would be more reliable.
Sorry, should have clarified. Axe 2 is connected to the left arm, axe 1 is connected to the HumanoidRootPart. I do think it’s a timing issue, but if I have to use a local script, is there some code that I have to change since I tried it already without changing the code and the animation just doesn’t play?
If you’re using a LocalScript, you would have to use the Animator on the Humanoid of your NPC
local animation = script:WaitForChild('Animation')
local humanoid = script.Parent:FindFirstChildOfClass('Humanoid')
local animator = humanoid:FindFirstChildOfClass('Animator')
animator:LoadAnimation(animation)
animation:Play()
I would have to have a visualization of where the markers are to really know if that is the problem, if you still want it server sided, you might be able to fix that.
I tried changing it to a local script, so here’s this (if there is a solution for server side I can revert back), but anyways, as for a local script it still isn’t animated so I think I did something wrong, just not sure what.
local function playAnimationFromServer(character, animation)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
-- need to use animation object for server access
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
return animationTrack
end
end
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local character = script.Parent
playAnimationFromServer(character, animation)
Okay so I could be wrong since I’m not the smartest when it comes to programming anything- but I think the script may not be running at all when it’s local script for some reason? I don’t see any of the prints inside of the client log thing- but also don’t see any errors related to it either.
Already tried this before with the exact same results- but also the animation still doesn’t play on a local script (and doesn’t sync on a normal script)