Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would i make it so you have to press 2 Buttons to run an animation with userinputservice?

Script:

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character

UIS.InputBegan:connect(function(input)
 if input.KeyCode == Enum.KeyCode.W then
  local Anim = Instance.new('Animation')
  Anim.AnimationId = 'rbxassetid://1667958741'
  PlayAnim = Character.Humanoid:LoadAnimation(Anim)
  PlayAnim:Play()
 end
end)

UIS.InputEnded:connect(function(input)
 if input.KeyCode == Enum.KeyCode.W then
  Character.Humanoid.WalkSpeed = 16
  PlayAnim:Stop()
 end
end)

1 answer

✓ Accepted answer

It doesn’t work due to deprecated code on lines 5 and 14. Change :connect to :Connect.

To check if two buttons are down (simultaneously) use the UserInputService:IsKeyDown( KeyCode keyCode ) method.

local UIS = game:GetService'UserInputService'
local keyCodeQ = Enum.KeyCode.Q
local keyCode_E = Enum.KeyCode.E

UIS.InputBegan:Connect(function(input, chatting)
    if chatting then
        return
    end

    if UIS:IsKeyDown(keyCodeQ) and UIS:IsKeyDown(keyCode_E) then
        -- do code
    end
end)

I used keys E and Q as an example. If both are down at the same time, code will execute.

9 comments

2

-_- Pretty sure connect does work. Why do you insist on forcing your standards on everyone?

0

Doesn’t. Connect does though.

2

Nope. It still works. Nevertheless, it is better to switch to Connect since connect could possible be removed in near future.

0

connect works.

0

Not having any issues from any of my places despite ALL of my scripts having connect in them, liar. Even the controlscripts still have connect in them.

1

I get the error "connect is not a valid member of RBXScriptSignal". And Zafirua that’s why people should switch to Connect.

0

The only problem is that i want the animation to stop whenever i release the keys.

0

I never got that error before tbh. No need to get mad though Melt, always better to use updated code.

0

Can someone make it so whenever i release the keys the animation stops?

This discussion is preserved as it was. New answers, comments, and votes are closed.