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

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

1 answer

✓ Accepted answer

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

2 comments

0

Thank you so much! Now I understand what's going on!

0

No problem. Glad to help.

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