Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why can players only switch the animations once?

I've been working with trying to get a walking crouch script to work but I can't get players to switch the animations more than once. The first animation plays when the player isn't moving and the second plays when the player does. The issue is the player will press ctrl causing the player to crouch which is good and they can move starting the second animation but when they stop they can never go back to the second animation when moving.

This is my script under ServerScriptService:

local uis = game:GetService("UserInputService")
local walking = Instance.new("BoolValue")
walking.Value = false
game.ReplicatedStorage.Crouch.Start.OnServerEvent:Connect(function(player)
	if walking.Value == false then
		walking.Value = true
  local Animation = Instance.new("Animation", player.Character)
  Animation.AnimationId = "rbxassetid://5010278985"
  Animate = player.Character.Humanoid:LoadAnimation(Animation)
	Animate.Priority = 1
  Animate:Play()
	wait()
	player.Character.Humanoid.Running:Connect(function(speed)
		while true do
			wait()
		if walking.Value == true then
	wait()
	Animate:Stop()
	local Animation2 = Instance.new("Animation", player.Character)
  Animation2.AnimationId = "rbxassetid://5062446283"
  Animate2 = player.Character.Humanoid:LoadAnimation(Animation2)
Animate2.Priority = 1
  Animate2:Play()

while true do
	wait()
	if speed <= 1 then
		walking.Value = false
		Animate2:Stop()
		Animate:Play()
	break
							
	end		
end
end
end
end)
end
end)
game.ReplicatedStorage.Crouch.End.OnServerEvent:Connect(function(player)
	walking.Value = false
  Animate:Stop()
Animate2:Stop()

end)

I've tried playing around with the walking value and loops but I can barely put my head around it. Basically, the second animation never plays again

1 answer

Fixed finally

local walking = Instance.new("BoolValue")
walking.Value = false
local Players = game:GetService("Players")


Players.PlayerAdded:Connect(function(player)
	wait(4)

local Animation = Instance.new("Animation", player.Character)
  Animation.AnimationId = "rbxassetid://5010278985"
  Animate = player.Character.Humanoid:LoadAnimation(Animation)
wait()

local Animation2 = Instance.new("Animation", player.Character)
	Animation2.Name = "Animation2"
	Animation2.AnimationId = "rbxassetid://5062446283"
	Animate2 = player.Character.Humanoid:LoadAnimation(Animation2)

end)



game.ReplicatedStorage.Crouch.Start.OnServerEvent:Connect(function(player)
	if walking.Value == false then
		walking.Value = true
		Animate:Play()
  
	end
end)


game.ReplicatedStorage.Crouch.End.OnServerEvent:Connect(function(player)
	walking.Value = false
	Animate:Stop()
	Animate2:Stop()
	
end)


game.ReplicatedStorage.Crouch.Start.OnServerEvent:Connect(function(player)
player.Character.Humanoid.Running:Connect(function(speed)
	if walking.Value == true and speed >= 1 then
		Animate:Stop()
		Animate2:Play()

		end
	end)
end)


game.ReplicatedStorage.Crouch.Start.OnServerEvent:Connect(function(player)
player.Character.Humanoid.Running:Connect(function(speed)
			if speed <= 0 and walking.Value == true then 
				Animate2:Stop()
				Animate:Play()
					
		end
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.