Like I said in the title, I’ve been wanting to create a script that depending on what key you’re pressing, the animation on your character will change so that the legs point to the direction in which you’re moving, for example: Say you’re pressing W+D to move diagonally, and while you do, an animation plays that rotates your hips towards that direction. Same goes for W+A. The issue is, none of the animations I’ve made for each scenario play, none of them do, and I’ve ran out of solutions. I don’t know what to do anymore. I’ve tried using UserInputService to detect in a function whether or not the player is pressing both W and A or W and D, I tried using ContextActionService and still nothing. I don’t know what I’m doing wrong, but here’s my code if it’s worth something:
local Player = game.Players:WaitForChild("LocalPlayer") local Character = Player:WaitForChild("Character") local Humanoid = Character:WaitForChild("Humanoid") local UIS = game:GetService("UserInputService") local animator = Humanoid:WaitForChild("Animator") local playing UIS.InputBegan:connect(function(input, processed) if processed then return end if UIS:IsKeyDown(Enum.KeyCode.D) and UIS:IsKeyDown(Enum.KeyCode.W) then local AnimD = Instance.new("Animation", Humanoid) AnimD.Name = "AnimD" AnimD.AnimationId = "rbxassetid://6842293003" local AnimDTrack = animator:LoadAnimation(AnimD) playing = AnimDTrack AnimDTrack:Play() elseif UIS:IsKeyDown(Enum.KeyCode.A) and UIS:IsKeyDown(Enum.KeyCode.W) then local AnimA = Instance.new("Animation", Humanoid) AnimA.Name = "AnimA" AnimA.AnimationId = "rbxassetid://6842289525" local AnimATrack = animator:LoadAnimation(AnimA) playing = AnimATrack AnimATrack:Play() elseif UIS:IsKeyDown(Enum.KeyCode.S) then local AnimS = Instance.new("Animation", Humanoid) AnimS.Name = "AnimS" AnimS.AnimationId = "rbxassetid://6842295145" local AnimSTrack = animator:LoadAnimation(AnimS) playing = AnimSTrack AnimSTrack:Play() end end) UIS.InputEnded:connect(function(input) playing:Stop() end)
What I’ve been trying to do more or less is to make my game’s movement more reallistic, so that when I go sideways or diagonally my character doesn’t just have the same walking animation all the time.