Changing AnimationIds in Animate Script doesn't work

Hi all, I have been trying to change the idle, running, and walking animations when a player equips a tool.

character.ChildAdded:Connect(function (child)
	if (child:IsA("Tool")) then
		child.Equipped:Connect(function (_m)
			if child:GetAttribute('Type') == 'Light Sword' then				
				character.Animate.run.RunAnim.AnimationId = 'rbxassetid://id'
				character.Animate.walk.WalkAnim.AnimationId = 'rbxassetid:/id'
				character.Animate.idle.Animation1.AnimationId = 'rbxassetid://id'
				character.Animate.idle.Animation2.AnimationId = 'rbxassetid://id'
			elseif child:GetAttribute('Type') == 'Heavy Sword' then
				character.Animate.run.RunAnim.AnimationId = 'rbxassetid://id'
				character.Animate.walk.WalkAnim.AnimationId = 'rbxassetid://id'
				character.Animate.idle.Animation1.AnimationId = 'rbxassetid://id'
				character.Animate.idle.Animation2.AnimationId = 'rbxassetid://id'
			end
		end)
	end
end)

From looking around in the forum I assumed that this would be an easy solution, but to my surprise it doesn’t work. I know that the values are being changed, since when I look at the Animate script in the workspace, the AnimationIds are changed. Not only that, but I also tried stopping all previous animations before changing these Ids, and that didn’t work.

The animations I’m using are for sure owned by my group, and the game is a part of the group. Maybe I am missing something obvious? I also looked around at changing the HumanoidDescription of the character, but since none of the Animations are children under a R15 folder, that won’t be a viable solution either. Any and all help would be appreciated.

In the script the ID says

'rbxassetid://id'

I dont know if you did this intentionally but maybe that is the problem?

That’s intentional. I don’t actually have it like that in the live script.

Are the animations being reloaded to the Humanoid when changed? I’m not too familiar with changing ids in the default Animate script, so this may not be the case.

I looked around in the default Animate script, and it doesn’t seem like they reload. I also failed to mention that I also tried loading them again in that script snippet.

character.Humanoid:LoadAnimation(character.Animate.walk.WalkAnim)
character.Humanoid:LoadAnimation(character.Animate.run.RunAnim)
character.Humanoid:LoadAnimation(character.Animate.idle.Animation2)
character.Humanoid:LoadAnimation(character.Animate.idle.Animation1)

I did that out of desperation. Of course, it didn’t work.

for one The animation script is already running, and the Ids Originally Declared are being used. After that, it doesn’t refer to the Bool Ids under it. You’d have to change the animation script to check for bool ids and load them up to the character on a regular basis.

da fuction was run too late cuz the tool is already equipped
its just the same when the tool is equipped it just parented into da character

Were you able to figure it out?

Hey! Sorry for the necropost, but yes, I did eventually figure out a solution to have multiple different animations play for multiple different weapons with no lag, well, lag when loading in a character, but smooth for the rest.

So, my solution was to create a Local Script in StarterScripts->StarterCharacterScripts called Animations.

local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Animator: Animator = Character.Humanoid.Animator
local CurrentlyPlaying: AnimationTrack = nil

local PlayerEvents = ReplicatedStorage.PlayerEvents

local ExampleAnimations = {
	'rbxassetid://nil',
	'rbxassetid://nil',
	'rbxassetid://nil',
	'rbxassetid://nil'
}

local ExampleAnimTracks = {}
for k, v in pairs(ExampleAnimations) do
	local animation = Instance.new('Animation')
	
	animation.AnimationId = v
	local animationTrack = Animator:LoadAnimation(animation)
	
	table.insert(ExampleAnimTracks, animationTrack)
end

function PlayAnimation(animationType: string, index: number)
	if animationType == 'Example' then
		CurrentlyPlaying = ExampleAnimTracks[index]
		for i,v in pairs(ExampleAnimTracks) do
			v:Stop()
		end
		ExampleAnimTracks[index]:Play()
	end
end

function StopAnimation(animationType: string, index: number)
	CurrentlyPlaying:Stop()
end

PlayerEvents.PlayAnimation.Event:Connect(PlayAnimation)
PlayerEvents.StopAnimation.Event:Connect(StopAnimation)

So, what it would do is connect to an Event that would pass through the name of an animations as well as the Index of which animation it would play. This is useful for combat games considering that you can create combos and things like that fairly easily by just keeping track of a number else where. If you or anyone else needs help understanding how this works just let me know.

You can also tack on more Animations to it by creating a new if statement and copying the syntax for ExampleAnimations and ExampleAnimTracks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.