1. Ensure the Animation Doesn’t Loop:
It sounds like the animation might be looping back to its starting position, causing the hand to go back down. You mentioned that the animation is not looped, but it’s worth double-checking the animation properties to ensure that it doesn’t loop.
In Roblox Studio, when you create or edit animations, ensure that the Looped property of the animation is unchecked:
- Go to the animation in ReplicatedStorage.
- Click on the animation and check the Looped property in the Properties panel.
- Make sure it’s set to
false
.
If the animation is being loaded correctly and it’s still looping, ensure the following:
2. Modify the Code to Stop the Animation After Playing:
Even if the animation is not looped, Roblox animations by default will return to their initial state once they are completed, causing the “down” movement. One way to handle this is by using the Stop()
function after the animation finishes.
You can stop the animation at the exact moment it finishes by using the track.Stopped
event.
Here’s how you can modify your code to stop the animation immediately after it plays:
Copiar código
-- // Variables
local plr = game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local armAnimation = game:GetService("ReplicatedStorage").Animations.ArmUpArmDown
local animator = humanoid:WaitForChild("Animator")
local track = animator:LoadAnimation(armAnimation)
-- // Main Function
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
-- Check if E is pressed
if gameProcessed then return end
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.E then return end
print("Pressed E")
track:Play() -- Play the Animation
-- Stop the animation once it's done to prevent it from going down
track.Stopped:Connect(function()
track:Stop()
end)
end)
3. Adjust the Animation Itself:
If the above solution doesn’t work as expected, the issue might be in the animation itself. Check if the animation has a “down” movement included at the end, which causes the hand to return to its original position.
You can modify the animation directly in Roblox Studio using the Animation Editor:
- Open the Animation Editor.
- Locate your animation (e.g.,
ArmUpArmDown
).
- Make sure the keyframe for the “up” position is the last keyframe, and that there’s no keyframe causing it to go back down.
- Save the changes and upload the new animation.
4. Consider Using a Custom Animation for the “Up” Movement:
If the current animation includes both the “up” and “down” movements, consider splitting them into two separate animations:
- One animation that raises the hand (without any downward movement).
- Another animation that returns the hand to the idle position (if needed).
You can then trigger these animations independently depending on the actions of the player.
Example of Playing Separate Animations:
Copiar código
-- // Variables
local plr = game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local armUpAnimation = game:GetService("ReplicatedStorage").Animations.ArmUp
local armDownAnimation = game:GetService("ReplicatedStorage").Animations.ArmDown
local animator = humanoid:WaitForChild("Animator")
local trackUp = animator:LoadAnimation(armUpAnimation)
local trackDown = animator:LoadAnimation(armDownAnimation)
-- // Main Function
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
-- Check if E is pressed
if gameProcessed then return end
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.E then return end
print("Pressed E")
trackUp:Play() -- Play the "Arm Up" animation
end)
This way, you can ensure the hand only goes up and doesn’t return down unless you specifically play the “ArmDown” animation later.
Conclusion:
To fix the issue, try:
- Ensuring the animation is not looped in Roblox Studio.
- Stopping the animation after it finishes using the
Stopped
event.
- If needed, split the “up” and “down” actions into separate animations for more control.
Let me know if you need further clarification or adjustments!