Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My animations (and speed adjustments) aren't working, does anyone know why?

Asked by 5 years ago
Edited 5 years ago

I was trying to make my first script on Roblox, which would be a script allowing a player to crouch by pressing LeftControl. The LocalScript is located in StarterCharacterScripts, in StarterPlayer. I have inserted 4 animations in the script with the correct name (and IDs), and I really don't know why this isn't working. My Roblox name is Natsukiko, and my name is in line 13 because it didn't work when it used to say "Player" instead (Player is not a valid member of Workspace). All the prints work as intended, but not the animations or speed adjustments.

crawlDown = nil
crawlUp = nil
crawlAnim = nil
crawlAnimIdle = nil
local humanoid = script.Parent.Humanoid

game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
 if input.KeyCode == Enum.KeyCode.LeftControl then
  game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed - 0.5
  crawlDown = humanoid:LoadAnimation(script.CrawlDown)
  print("Started crouching")
  wait(0.15)
  game.Workspace.Natsukiko.Humanoid.Running:connect(function(speed)
    if speed > 0 then
        crawlAnim = humanoid:LoadAnimation(script.CrawlAnim)
        print("Moving")
    else
        crawlAnimIdle = humanoid:LoadAnimation(script.CrawlAnimIdle)
        print("Standing still")
   end
  end)
 end
end) 

game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
 if input.KeyCode == Enum.KeyCode.LeftControl then
    crawlUp = humanoid:LoadAnimation(script.CrawlUp)
    print("Going up")
    game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed + 0.5
 end
end)

Answer this question