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

Is there a function or event that plays when the player presses on WASD?

Asked by 5 years ago

So, I am trying to make a boat move, but.. It doesn't, I used a Vehicle seat and it still didn't work. I used rotors but I don't have control over them. any ideas?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Hi mix,

The UserInputService's InputBegan event is activated everytime you press anything on the keyboard or the mouse. So, use that event and use its two parameters, input and gameProcessedEvent, to find out if the key that was pressed was WASD and if it was a gameProcessedEvent. So, something like this would probably do:

local keys = {
    ["W"] = true;
    ["A"] = true;
    ["S"] = true;
    ["D"] = true;
}
local uis = game:GetService("UserInputService");

uis.InputBegan:Connect(function(input, gp)
    if keys[input.KeyCode.Name] and not gp then 

--[[ input is the key that was pressed and gp is a boolean that is true if the key was pressed while the person was typing(as in chat or something). So, you need to check that it's not gp if you don't want the function to activate while they're typing. --]]

        -- Blah blah blah. Do whatever you want, from here on it's WASD territory.
    end
end)

Hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
Thank you so much! Now I understand what's going on! mixgingengerina10 223 — 5y
0
No problem. Glad to help. KingLoneCat 2642 — 5y
Ad

Answer this question