I’m trying to make it so that the player can’t move if he plays the animation, but sometimes the script doesn’t work and the player can walk with the animation
My code:
local Keys = {
["v"]={Render,true}, -- Segunda variavel confirma se o player pode correr
["c"]={Agachar,false},
["j"]={Continencia,true},
["f"]={MaoTras,true}
}
local State
Humanoid.Running:Connect(function(speed)
if speed > 0 then
State = "andando"
else
State = "parado"
end
end)
Mouser.KeyDown:Connect(function(key)
local KeyFind = Keys[key]
if KeyFind and InAnimation == false and State == "parado" then
InAnimation = true
local AnimTrack = KeyFind[1]
if KeyFind[2] == false then
coroutine.wrap(function()
while true do
if InAnimation == true then
print("InAnimation")
CanRun.Value = false
Humanoid.WalkSpeed = 0
Humanoid.JumpHeight = 0
else
print("OutAnimation")
CanRun.Value = true
Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
Humanoid.JumpHeight = game.StarterPlayer.CharacterJumpHeight
break
end
wait()
end
end)()
end
AnimTrack:Play()
AnimTrack:AdjustSpeed(0)
elseif KeyFind and InAnimation == true and State == "parado" then
local AnimTrack = KeyFind[1]
if AnimTrack.IsPlaying == true then
AnimTrack:Stop()
if KeyFind[2] == false then
CanRun.Value = true
Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
Humanoid.JumpHeight = game.StarterPlayer.CharacterJumpHeight
end
InAnimation = false
end
end
end)