Animation not updating after being changed

Maybe try doing this:

char.Running:Connect(function()
crouchloadanim:Play()
crouchloadanim:AdjustSpeed(1)
end)

char.Idle:Connect(function()
crouchloadanim:AdjustSpeed(0)
end)
1 Like

I would try that, but there is not a variable called crouchloadanim. Could you explain what that is?

he’s probably referring to what i said

Basically, create an animation inside your script and name it Crouch. Then create a variable called crouchanim. Then I’ll show you what to do next:

image

local crouchanim = script:WaitForChild("Crouch")
local crouchloadanim = char.Humanoid:LoadAnimation(crouchanim)

char.Running:Connect(function()
crouchloadanim:Play()
crouchloadanim:AdjustSpeed(1)
end)

char.Idle:Connect(function()
crouchloadanim:Play()
crouchloadanim:AdjustSpeed(0)
end)

How would that change the walk and idle animation…?

Have you scripted the character to play the crouch idle animation as you transition from crouching to fully crouched?

It will detect if the humanoid is idling and it’ll play the animation and if the humanoid is running, it’ll adjust the animation speed to 1 and play the animation too.

Idle is not a valid member of character.

Oh then do character.Humanoid sorry about that.

It’s also not a valid member of humanoid…

I think it’s:

player.Idled:Connect(function()-- the player is not the character by the way.

end) 


the player is not the character by the way.

Well, testing the other code turns up working, however, the function does not fire. My best guess as to why this would be is that the idled function is only called when the player begins idling. Is there a way to tell if the player is currently idle?

Maybe try doing this:

local crouchanim = script:WaitForChild("Crouch")
local crouchloadanim = char.Humanoid:LoadAnimation(crouchanim)

    if  char.Animate.idle.Animation1:Play() or char.Animate.idle.Animation2:Play() then  
    crouchloadanim:Play()
    end

That doesn’t work, those aren’t loaded animations.

A quick google gave me the answer to that problem. Now I just need to figure out when they stop idling/running.

Alright, got it done now. Thanks for the help! I probably wouldn’t have thought of the play animation thing otherwise.

Final script that is still a bit jittery but works soooo
local animEvent = script.Parent:WaitForChild("CrouchEvent")
local player = game.Players.LocalPlayer
local team = player:WaitForChild(player.Name .. "_Team")
local crouching = false
local crouchAnim = game:GetService("ReplicatedStorage").Animations.Crouch.Crouch
local unCrouchAnim = game:GetService("ReplicatedStorage").Animations.Crouch.UnCrouch
local idle = game:GetService("ReplicatedStorage").Animations.Crouch.Idle
local running = game:GetService("ReplicatedStorage").Animations.Crouch.Running
local loaded
local debounce = false
local chr
local loaded_anim

local oldMoveDirection

local heightScale

local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(0.6, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
local crouchTween

animEvent.Event:Connect(function()
	if loaded ~= nil then
		loaded:Stop()
	end
	
	if team.Value == "Survivor" and crouching == false and debounce == false then
		chr = player.Character
		
		debounce = true

		crouching = true
	
		loaded = chr.Humanoid:LoadAnimation(crouchAnim)
		loaded:Play()
		
		chr.Animate.idle.Animation1.AnimationId = "rbxassetid://6947538908"
		chr.Animate.idle.Animation2.AnimationId = "rbxassetid://6947538908"
		chr.Animate.walk.WalkAnim.AnimationId = "rbxassetid://6947559461"
		chr.Animate.run.RunAnim.AnimationId = "rbxassetid://6947559461"
		
		loaded_anim = chr.Humanoid:LoadAnimation(chr.Animate.idle.Animation1)
		loaded_anim = chr.Humanoid:LoadAnimation(chr.Animate.idle.Animation2)
		loaded_anim = chr.Humanoid:LoadAnimation(chr.Animate.walk.WalkAnim)
		loaded_anim = chr.Humanoid:LoadAnimation(chr.Animate.run.RunAnim)
		
		crouchTween = TweenService:Create(chr.Humanoid, TweenInfo, {HipHeight = chr.Humanoid.HipHeight / 2.5})
		crouchTween:Play()
		
		print "Crouching"
		
		wait(0.6)
		
		chr.Humanoid.WalkSpeed = 11.25
		
		debounce = false
		
		idle.AnimationId = "rbxassetid://6947538908"

		running.AnimationId = "rbxassetid://6947559461"
		
		if chr.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then  
			loaded = chr.Humanoid:LoadAnimation(idle)
			loaded:Play()
			loaded:AdjustSpeed(0)
		else
			loaded = chr.Humanoid:LoadAnimation(running)
			loaded:Play()
			loaded:AdjustSpeed(1)
		end
		
		oldMoveDirection = chr.Humanoid.MoveDirection
		
		chr.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
			if oldMoveDirection == Vector3.new(0, 0, 0) then
				loaded:Stop()
			elseif not (oldMoveDirection ~= Vector3.new(0, 0 ,0) and chr.Humanoid.MoveDirection ~= Vector3.new(0, 0, 0)) then
				loaded:Stop()
			end
		end)
	elseif team.Value == "Survivor" and debounce == false then
		debounce = true
		
		crouching = false
		
		loaded = chr.Humanoid:LoadAnimation(unCrouchAnim)
		loaded:Play()
		
		chr.Animate.idle.Animation1.AnimationId = "rbxassetid://6982673549"
		chr.Animate.idle.Animation2.AnimationId = "rbxassetid://6982673549"
		chr.Animate.walk.WalkAnim.AnimationId = "rbxassetid://6943155748"
		chr.Animate.run.RunAnim.AnimationId = "rbxassetid://6943155748"
		
		loaded_anim = chr.Humanoid:LoadAnimation(chr.Animate.idle.Animation1)
		loaded_anim = chr.Humanoid:LoadAnimation(chr.Animate.idle.Animation2)
		loaded_anim = chr.Humanoid:LoadAnimation(chr.Animate.walk.WalkAnim)
		loaded_anim = chr.Humanoid:LoadAnimation(chr.Animate.run.RunAnim)
		
		crouchTween = TweenService:Create(chr.Humanoid, TweenInfo, {HipHeight = chr.Humanoid.HipHeight * 2.5})
		crouchTween:Play()
		
		print "Not Crouching"
		
		wait(0.6)
		
		chr.Humanoid.WalkSpeed = 18
		
		debounce = false
		
		idle.AnimationId = "rbxassetid://6982673549"

		running.AnimationId = "rbxassetid://6943155748"

		if chr.Humanoid.MoveDirection == Vector3.new(0, 0, 0) then  
			loaded = chr.Humanoid:LoadAnimation(idle)
			loaded:Play()
			loaded:AdjustSpeed(0)
		else
			loaded = chr.Humanoid:LoadAnimation(running)
			loaded:Play()
			loaded:AdjustSpeed(1)
		end

		oldMoveDirection = chr.Humanoid.MoveDirection

		chr.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
			if oldMoveDirection == Vector3.new(0, 0, 0) then
				loaded:Stop()
			elseif not (oldMoveDirection ~= Vector3.new(0, 0 ,0) and chr.Humanoid.MoveDirection ~= Vector3.new(0, 0, 0)) then
				loaded:Stop()
			end
		end)
	end
end)
3 Likes

Glad you solved your problem! I hope you have a lovely day!

1 Like

Okay, so I found a solution.
How to works, is it checks if an ID was changed for any Animation Instances in Roblox’s default animate script then changes its humanoidStateType to update the animations, so I grabbed the animate script and added the code under the “connect events” as seen in the image. I don’t know if this is the most efficient way, so please if someone has something else that works just as smoothly and similar to this then please, let us know.

I hope this helped you.

spawn(function()
	for i,v in pairs(script:GetChildren()) do
		for i2, anim in pairs(v:GetChildren()) do
			if anim:IsA("Animation") then
				spawn(function()
					anim:GetPropertyChangedSignal("AnimationId"):Connect(function()
						Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
					end)
				end)
			end
		end
	end
end)

14 Likes

This script by itself didn’t work for me as it seemed to be running the code before the animations were loaded. I added a line to wait for the animations to load and it worked perfectly.

Code, inside the Animate script, which I put in StarterCharacterScripts

task.spawn(function()
	repeat task.wait() until #script:GetChildren() == 10
	for i,v in pairs(script:GetChildren()) do
		for i2, anim in pairs(v:GetChildren()) do
			if anim:IsA("Animation") then
				task.spawn(function()
					anim:GetPropertyChangedSignal("AnimationId"):Connect(function()
						Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
					end)
				end)
			end
		end
	end
end)

Just leaving this here for any future developers. Thanks, @DabidarZ

2 Likes

This script works on the client’s side, but the server doesn’t seem to register it for me. Do you know how to fix that? I tried to implement this script in a server script, but it doesn’t seem to do anything for me.

1 Like

Did you put it inside an Animate script? And what do you need it on the server for, npcs?

I did put it in the Animate script, and I tried to put that script in a server script afterwards to test if it was the client not replicating to the server or something.

1 Like