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

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

Asked by
exarlus 72
5 years ago

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

Log in to vote
1
Answered by 5 years ago

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.

2
-_- Pretty sure connect does work. Why do you insist on forcing your standards on everyone? Meltdown81 309 — 5y
0
Doesn’t. Connect does though. User#19524 175 — 5y
2
Nope. It still works. Nevertheless, it is better to switch to Connect since connect could possible be removed in near future. Zafirua 1348 — 5y
0
connect works. theCJarmy7 1293 — 5y
View all comments (5 more)
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. Meltdown81 309 — 5y
1
I get the error "connect is not a valid member of RBXScriptSignal". And Zafirua that’s why people should switch to Connect. User#19524 175 — 5y
0
The only problem is that i want the animation to stop whenever i release the keys. exarlus 72 — 5y
0
I never got that error before tbh. No need to get mad though Melt, always better to use updated code. TiredMelon 405 — 5y
0
Can someone make it so whenever i release the keys the animation stops? exarlus 72 — 5y
Ad

Answer this question