How can I stop a loop of an animation?

I’m fed up with animations, whenever I make one, it loops (I don’t know if the priority of the animation influences, which in this case is action). I don’t really see any problem, I have other scripts absolutely the same and they work without looping, and I don’t know how to eliminate the damn loop

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

local toolsFolder = ServerStorage:WaitForChild("ToolsFolder")
local HungerAndThirstIncrease = ServerStorage:WaitForChild("HungerAndThirstIncrease")

local ProfileService = require(ServerScriptService:WaitForChild("DataStore"):WaitForChild("Configurations"):WaitForChild("DataManager"))

local stack = script.Parent:WaitForChild("Stack")


local tool = script.Parent
local animator
local debounce = false
local del = 1.2

local loadedAnims = {}
local anims = {
	["Eat_Animation"] = tool:WaitForChild("Animations"):WaitForChild("Eat");
	["Drink_Animation"] = tool:WaitForChild("Animations"):WaitForChild("Drink");
	["Curate_Animation"] = tool:WaitForChild("Animations"):WaitForChild("Curate");
}

tool.Activated:Connect(function()
	local char = script:FindFirstAncestorWhichIsA("Model")
	local Player = Players:GetPlayerFromCharacter(char)

	local Humanoid = char:WaitForChild("Humanoid")

	local Backpack = Player:WaitForChild("Backpack")
	local PlayerGui = Player:WaitForChild("PlayerGui")

	local Activatedtool = PlayerGui:WaitForChild("MenuDeMapa"):WaitForChild("Slots"):WaitForChild("ActivatedTool")
	local Profile = ProfileService:Get(Player, false)

	local animator = Humanoid:WaitForChild("Animator") 
	local CharacterServices = Profile.Data.PlayerServices.CharacterServices

	if(not loadedAnims["Curate_Animation"]) then loadedAnims["Curate_Animation"] = animator:LoadAnimation(anims["Curate_Animation"]) end
	loadedAnims["Curate_Animation"]:Play()
end)

AnimationTracks have a Looped property, set this to false when you’re loading your animations,

loadedAnims["Curate_Animation"] = animator:LoadAnimation(anims["Curate_Animation"])
loadedAnims["Curate_Animation"].Looped = false

Also just a little fyi, you can eliminate the whole if-statement by doing

loadedAnims["Curate_Animation"] = loadedAnims["CurateAnimation"] or animator:LoadAnimation(anims["Curate_Animation"])
2 Likes

I get an error that says Looped is not a valid member of Animation

Edit: sorry, I had the wrong place to put that part of Looped = false. Well I already did that and it doesn’t give me any error, however it doesn’t stop the loop

			loadedAnims["Curate_Animation"] = loadedAnims["CurateAnimation"] or animator:LoadAnimation(anims["Curate_Animation"])
			loadedAnims["Curate_Animation"].Looped = false
			loadedAnims["Curate_Animation"]:Play()

Do you mean track:Stop() or track:Pause()?

Looped is a property of the animation track, not the Animation (note the looped property is bugged (last I checked) and doesn’t replicate properly to the client, so if you basically can’t use it from the server and some other cases).

Cody is talking about the looped setting when you create an animation. This is probably what you want to change. To do this, reupload the animation but go into the settings and set looping to false.

Edit:
Here is the super old bug report that Roblox never got around to fixing :slight_smile:

You’re attempting to change animationObject.Looped which doesn’t exist.The animation track differs from the animation object itself. The animation track is the variable that loads the animation and plays. Animation Track Loop Dev Documentation

Heads up! The animationTrack.Looped variable doesn’t replicate from server to client. Roblox bug stuff. Retrieving animationTrack on client-side set by server would be by using " Humanoid:GetPlayingAnimationTracks()" But since loop doesn’t replicate be careful when using this.

The solution

local animation  = animationObject-- set as the animation object
 
local animationTrack = humanoid:LoadAnimation(animation)--Animation track
animationTrack.Looped = false
animationTrack:Play()

Other Cool Facts Of Animation Tracks That Can Help Increase The Quality Of Your Creations

The animationTack also has events that you can line up with animation keys when creating the animation. Or other events based on the current animation progress. Animation Track Documentation. Scroll to Events section

An example of using these events would be setting a keyframe in the animation

Example of animationTrack keyframe event

local animation  = animationObject-- set as the animation object
 
local animationTrack = humanoid:LoadAnimation(animation)--Animation track
animationTrack.Looped = false
animationTrack:Play()

local forceKeyFrameName= "ArmRaise"--As in using the force
animTrack.KeyframeReached:Connect(function(keyframeName)--Reached a keyframe
    if keyframeName == forceKeyFrameName then--reached key frame is the same as the "start using the force" keyframe
        self:UseForce(self.Target)--Module script example that theoretically would raise the object as if player was using the force.
    end
end)

animTrack:Stopped:Connect(function()--Animation ended so stop using force aka drop object that forced was used on.
    self:StopUsingForce(self.Target)--Theoritical module script that would stop using the force.
end)
1 Like

AnimationTrack:Stop()

https://developer.roblox.com/en-us/api-reference/function/AnimationTrack/Stop

1 Like

Thanks for trying to help me and stuff, but sadly it doesn’t work for me. I’m a bit slow to understand things, and from what I have read, animations that are activated from the server, sometimes they are not replicated on the client? Maybe I should change the whole script to a localscript, before it was localscript but now it is server script because of ProfileService themes. I think I will do all this with LocalScript, since the complete script is to increase the life, food and thirst of the player, all because the data is in the ProfileService. I will add a remote event that does the rest of the function and that only the localScript does the animations

Here just read this. Animation Track Documentation

It has an example with an explanation of how it works. An animation track is a new variable that binds the animation object to the player’s characters/player’s character’s humanoid. In your script, you would be doing this by

animator:LoadAnimation(anims["Curate_Animation"]

As long as “loadedAnims[“Curate_Animation”]” is considered a animationTrack and not a nil value. And is separate from the AnimationObject. Then you should have a loadedAnims[“Curate_Animation”].Looped variable. Perhaps you using “:Looped” or misspelling it.

The error “Looped is not a valid member of Animation” means that for some reason loadedAnims[“Curate_Animation”] is an AnimationObject and not an AnimationTrack. Otherwise, it would not have an error, or be returning “AnimationTrack” rather than “Animation”

Could you provide me the video of the problem?

1 Like

Try loading the animation in the beginning of the script.
like
local SwordAnimation = Humanoid:LoadAnimation(“workspace.Animation”)

and you can play and stop it anytime (works for not loop)
tool.Activate:Connect(function()
SwordAnimation:Stop()
end)

or another way is to stop all animations

local getanim = hum:GetPlayingAnimationTracks()
for i,animation in pairs(getanim) do
animation:Stop()
end

Hope it helps !

1 Like

Yes, in fact it no longer gives me the error, it gave it to me for some reason but it simply no longer gives it to me, and it is not an Animation Object but a normal animation

I have the same issue. And I still couldnt fix it. Did you find any working solution for it ?