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

Animation script not working, confirmed LocalScript in StarterCharacterScripts..?

Asked by 6 years ago
Edited 6 years ago

I'm not sure why this isn't working. There is no problem with the names of the SeatParts or the location of the LocalScript (in StarterCharacterScripts) as far as I know:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local character = Player.Character
local humanoid = character:WaitForChild("Humanoid")

anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=1592193121"
anim2 = Instance.new("Animation")
anim2.AnimationId = "http://www.roblox.com/asset/?id=1621754495"
local animateScript = character.Animate


local function onInputBegan(input,gameProcessed)
  if gameProcessed then
    return
  end
  if input.UserInputType == Enum.UserInputType.Keyboard then
    local keyPressed = input.KeyCode
    if input.KeyCode == Enum.KeyCode.F and humanoid.Sit == true then
      if humanoid.SeatPart.Name == "R" then
        playAnim = humanoid:LoadAnimation(anim)
        playAnim:Play()
      elseif humanoid.SeatPart.Name == "L" or humanoid.SeatPart.Name == "DriveSeat" or humanoid.SeatPart.Name == "VehicleSeat" then
        playAnim2 = humanoid:LoadAnimation(anim2)
        playAnim2:Play()
      end
    end
  end
end

local function onInputEnded(input,gameProcessed)
  if gameProcessed then
    return
  end
  if input.UserInputType == Enum.UserInputType.Keyboard then
    local keyPressed = input.KeyCode
    if input.KeyCode == Enum.KeyCode.F and humanoid.Sit == true then
      local ActiveTracks = humanoid:GetPlayingAnimationTracks()
      for _,v in pairs(ActiveTracks) do
        if v.Priority == Enum.AnimationPriority.Action then
          v:Stop()
        end
      end
    end
  end
end

UserInputService.InputBegan:connect(onInputBegan)
UserInputService.InputEnded:connect(onInputEnded)
0
It's probably the seat that puts the character into a sitting position (which stops your animation from working) hellmatic 1523 — 6y

Answer this question