Need Help Stopping/Playing Animations At Certain Points

Hello Developers!

I’m building with the Build It Play It Roblox animation challenge. I have made an animation, but I only want it used in the obstacle course (not in the lobby). In the lobby, I’d like the regular Roblox walk animation.

Here are some videos:

My Animation In The Lobby (What I Don't Want)

My Animation Inside The Obstacle Course (What I Want To Keep) (Once you play the video the blur goes away.)

I’m guessing maybe you could do this with script? Here are some of the things I found that could help:

WalkAnimationID Properties (The Value Property Sets The Animation)

Annotation 2020-08-09 174040

My Explorer

To find my explorer, make a new project in Roblox Studio and click the Move It Simulator template, then look in the explorer; this will be the same as the explorer I have.

I found a script called AnimReplace inside of ServerStorage > AnimationManagement > Scripts (don't know if this will help)
-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")


-- Events
local Events = ReplicatedStorage.Events
local UpdatePointsEvent = Events.UpdatePoints


-- Variables
local Animations = ServerStorage.Animations
local replacementAnimations = {
	{ 
		name = "run", 
		id = (Animations.WalkAnimationID.Value ~= "" 
				and "http://www.roblox.com/asset/?id=" .. Animations.WalkAnimationID.Value) or "",
		isLoaded = false,
	},
	{
		name = "idle", 
		id = (Animations.IdleAnimationID.Value ~= "" 
				and "http://www.roblox.com/asset/?id=" .. Animations.IdleAnimationID.Value) or "",
		isLoaded = false,	
	},
	{
		name = "cheer", 
		id = (Animations.CheerAnimationID.Value ~= "" 
				and "http://www.roblox.com/asset/?id=" .. Animations.CheerAnimationID.Value) or "",
		isLoaded = false,
	},
}


-- Local Functions
local function onCharacterAdded(character)
	wait(1) -- You want to wait for the Animate script to load and run
	
	local humanoid = character:WaitForChild("Humanoid")
	for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingTracks:Stop(0)
	end
 
	local animateScript = character:WaitForChild("Animate")
	
	for _, anim in ipairs(replacementAnimations) do
		if not anim.isLoaded then continue end

		local animations = animateScript:WaitForChild(anim.name):GetChildren()
		-- Overwrite the IDs of all idle animation instances
		for _, animVariant in ipairs(animations) do
			animVariant.AnimationId = anim.id

			-- If you really want to prevent the animations from being changed by something else you could do this too
			animVariant:GetPropertyChangedSignal("AnimationId"):Connect(function()
				animVariant.AnimationId = anim.id
			end)
		end
	end
	
	-- Stop all currently playing animation tracks on the player
	for _, playingAnimation in pairs(humanoid:GetPlayingAnimationTracks()) do
		playingAnimation:Stop()
		playingAnimation:Destroy()
	end
end
 
local function onPlayerAdded(player)
	--Only run this code if an animation actually is loaded in. 
	local character = player.Character or player.CharacterAdded:wait()
	onCharacterAdded(character)
end


-- On Startup
for _, anim in ipairs(replacementAnimations) do
	--Check if there is an animation to load, if so, continue this script.
	if anim.id ~= "" then
		print("Valid Animation ID found. Replacing default animation")
		anim.isLoaded = true
	else
		warn(anim.name.." animation ID is blank. Keeping default animation")
	end	
end


-- Connections
Players.PlayerAdded:Connect(onPlayerAdded)

I appreciate any suggesstions! Thank you for your help!

Happy Building! :hammer_and_wrench:
~ Blox

What you’re going to do is use an if statement. Check if the player is supposed to be in the lobby or the obstacle course. If they are, set the animation to default walking, and if they aren’t then set it to the walk animation. You can also hook up an event that fires when the player switches places and then change their animation

I would put this in the animation script. Because I’m not allowed to write your scripts for you on the Forums, you have to decide where this goes and how to actually implement it.

How would you check where the player is? (I’m very new to scripting)

Also how would you change the animation using script?

While I’m not familiar with the project setup as I only skipped through it for the prizes, check around for any references that show whether the player is in the lobby or not. I would look around that button that lets the player get into the game and see if there’s a value or something. Otherwise, you can always just connect an event that switches the animations to whenever the button to get into the game is pressed.

You can just copy what the Replace Animation script does, specifically

The way this works is it gets all of the animations in the default roblox player animate script, and changes their IDs.