you should probably rewrite your code.
all it takes is a function that controls the animation your script is messy;
function animate(object, animationId, animator)
object.AnimationId = animationId
local new_animations = animator:LoadAnimation(object)
return new_animations
end
so change your code to this:
animEvent.Event:Connect(function()
if team.Value == "Survivor" and crouching == false and debounce == false then
chr = player.Character
debounce = true
crouching = true
--//you can set this var as local or make it global; you can
--you can set another crouch for crouch idle animation too.
crouch = animate(the run object, the crouch animationid, and the humanoid) --pseudo code.
crouch:Play()
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
elseif team.Value == "Survivor" and debounce == false then
debounce = true
crouching = false
loaded = chr.Humanoid:LoadAnimation(unCrouchAnim)
loaded:Play()
crouch:Stop()
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
end
end)
This code doesn’t change the walking animations and the idle animations, which is what the problem is. When the walking animation changes, it doesn’t change in-game until you stop moving. When the idle animation changes, it doesn’t change in-game until you start moving. The reason for the many lines of code that look extremely similar is that they are changing the walking and idle animations.
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.
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?
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
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)
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
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.