I’m quite new to LUA scripting via Roblox, and i’ve been at this project for a while now. I’m trying to tell the script that when W, A, S, or D is held down, to stop the idle animation and play the walking animation. But I can’t seem to figure out how to call multiple KeyCodes at once, and i’m also having a problem with whenever i press any other key while the walking animation is going, it will stop?
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local mouse = game:GetService("UserInputService")
local combat = script.Parent
local anim = humanoid:LoadAnimation(combat:WaitForChild("idle"))
local walk = humanoid:LoadAnimation(combat:WaitForChild("walking"))
combat.Equipped:Connect(function()
anim:Play()
mouse.InputBegan:connect(function(key)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode.W then
anim:Stop()
walk:Play()
mouse.InputEnded:connect(function()
walk:Stop()
anim:Play()
end)
end
end
end)
end)
combat.Unequipped:Connect(function()
anim:Stop()
end)