I’m trying to script my tool so that when it is picked up, there is no raising animation and the player instantly holds the tool straight out. I still want the player to hold the frisbee normally like in the picture, just skip the raising animation part. I don’t really know where to start with this.
I believe you’ll want to immediately play the animation for holding the tool straight out right after the tool has been equipped.
It should be as simple as copying the default tool holding animation ID and implementing it into your own tool, perhaps this post could be of help?
If you need further help, I’ll be happy to explain as best I can.
It works, however, now the player never puts their arm down. I run this function when first thing when the tool is equipped:
function skipAnimation(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=507768375" --toolnone
if humanoid then
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
return animationTrack
end
end
end
The player never puts their arm down because, well, your code is running as expected. I believe you only made it play the animation when the tool is equipped, and there’s nothing done when the tool is unequipped.
You’ll want to cache the animationTrack
variable outside of the equipped function, and make it stop the animationTrack when the tool is unequipped. Something like this:
local animationTrack = nil -- initialize the variable so it can be set in the skipAnimation function
local tool = script.Parent -- given the script is parented directly to the Tool
tool.Unequipped:Connect(function()
if animationTrack then
animationTrack:Stop()
end
end)
In your function skipAnimation
, you will want to remove the local
when assigning the animationTrack
variable, so that it’ll look like this:
animationTrack = animator:LoadAnimation(animation)
Sorry for the wait! Hope this helps.
Edit: I’ve also noticed that you’re creating a new Animation
every time the tool is equipped, specifically this:
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animation = Instance.new("Animation")
Over time, this will stack up and might cause performance issues. Before creating the Animation
object, you should preinitialize a variable just like we did with the animationTrack
, and check if there is an existing Animation
object before making a new one. This should work:
Outside of the skipAnimation
function (somewhere above it):
local animation = nil
Inside of the skipAnimation
function:
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not animation then
animation = Instance.new("Animation")
end
Unfortunately, I made a mistake. It turns out the function I provided you never worked. Running the toolnone animation doesn’t do anything. The only time it worked was when the player never put their arm down. I’m thinking I just make my own animation that instantly sticks the arm out and then the code you wrote would still be relevant.
I just tried it and I don’t think it is possible. I made an animation that is just the player sticking their arm straight out and it still does the raise. Roblox automatically tweens the arm from the resting position to the position of the animation. So the solution would be to stop that tweening from happening. Maybe at this point I have the player always sticking their arm out, or stick it out when the frisbee gets close to them.