I managed to do the animation part, but I still don't like it. (If possible, could anyone teach me how to make it that when e is not pressed anymore, the animation stops? I followed a crawl tutorial and I can barely understand what's going on here. I want to learn lua, but all I know is very basic Java)
leaning = false
local humanoid = script.Parent.Humanoid
crawlAnim = nil
crawlAnimIdle = nil
game:GetService("UserInputService").InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if leaning == true then
leaning = false
crawlAnim:Stop()
crawlAnim:Destroy()
crawlAnimIdle:Stop()
crawlAnimIdle:Destroy()
humanoid.WalkSpeed = humanoid.WalkSpeed*2
else
leaning = true
crawlAnim = humanoid:LoadAnimation(script.CrawlAnim)
crawlAnimIdle = humanoid:LoadAnimation(script.CrawlAnimIdle)
humanoid.WalkSpeed = humanoid.WalkSpeed/2
end
end
end)
while wait()do
if leaning == true then
crawlAnim:AdjustSpeed(humanoid.WalkSpeed/4)
if humanoid.MoveDirection ~= Vector3.new(0,0,0)then
if crawlAnim.IsPlaying ~= true then
crawlAnim:Play()
end
else
crawlAnim:Stop()
crawlAnimIdle:Play()
end
end
end
