Hi, I have created an animation that is supposed to make the users arm go up when the user clicks the mousebutton1 down. I want it to remain in that position until the user lets go of the mousebutton1, but it doesn’t seem to be working for me. Right now I have two scripts, one for when the user presses the mouse down and one when the user lets go. Its weird because when I put a simple print statement inside the mousebuttondown it prints down like its supposed to then when the mousebutton up runs it prints up. But for some reason the animation wont run while the mouse button is down. The only way I get the animation to work is if I click quick which is not what I want.
down.OnServerEvent:Connect(function(player)
local Character = player.Character
heldDown = true
local animation = Character.Humanoid:LoadAnimation(script.Parent.Animation)
animation:Play() -- Supposed to play the animation when the user holds down the mouse button
while wait(.5) and heldDown do -- Don't worry about this that is
vMult = vMult + 1 -- something else
end
end)
If somebody could lead me in the right direction that would be great, or if you need me to specify more just let me know.
Thanks, Saka!
Hello! It appears that you are running this script on the server. Is there any particular reason for this? You might want to try playing the animation from a LocalScript. Also, you might want to try playing the animation a few seconds after you load it. You could load the animation before the click event, for example. Let me know if this helps! If not perhaps we can find another solution.
I forgot to reply on your post, let me resend it lol. Hey! Thanks for responding, I am running this on the server instead of locally because isn’t that the only way that the other players on the server can see the animation? I have tried playing the game animation after it is loaded but it is weird since it still only runs when I click and let go. What I have noticed though is that if I hold down my item for a certain amount of time it actually does run in the background since I notice it wont run at all after holding it down for a while. I was able to make this connection since when I run it by clicking quickly it still runs, but for some reason sped up. Also I have tried running it through a local script and it doesn’t make a difference unfortunately.
Hmmm, interesting. Generally for player animations you can play them on the client. It might sound funny, but it is how Roblox handles them. The server will replicate them to other players anyway. You can take a look at this link if you want: Animation | Documentation - Roblox Creator Hub. Is the animation looped so that it plays continuously, or paused on a frame? And are you calling :Stop() when the mouse button is released? If it still won’t work, it might help if you could attach some pictures or even a video of what is occurring.
Ok so I created an unlisted video on youtube so you can view the problem easily. This is the problem I am having:
The code I posted above in the original post is what goes along with this, this is still the server script. I will take a code snippet of the client side one to see if this is what you mean
UserInputService.InputBegan:Connect(function(input, gameProc)
if gameProc then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and Equipped
then
animation:Play()
down:FireServer()
end
end)
UserInputService.InputEnded:Connect(function(input, gameProc)
if gameProc then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and Equipped
then
animation:Stop()
up:FireServer()
end
end)
So this is the local version of what you told me, although this does nothing at all for the character. I thought it would at least run the animation to bring his arm up but it doesn’t even do that. I am not sure if this is what you wanted me to do but this is what I tried. @Vrythex
Interesting. Thanks for the video, that helps a lot. What priority are you playing the animation on? If you are not playing the animation at a high priority, that might be your issue. Let me know if this fixes it for you.
That actually worked! If I am being honest I totally forgot about animation priority . Now when I click the arm raises, but it also lowers in the same loop. Is there anyway I could freeze the arm mid air so then I could stop it when he lifts up the mouse?