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

How do I use Keystrokes?

If I were to make KeyStrokes, would this LocalScript work?

Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
KeyStroke = {}

mouse.KeyDown:connect(function(key)
	if key == "s" then
		table.concat(KeyStroke, "s")
	end
	if key == "d" and KeyStroke[1] == "s" then
		table.concat(KeyStroke, "d")
	end
	if key == "q" and KeyStroke[1] == "s" and KeyStroke[2] == "d" then
		table.concat(KeyStroke, "q")
		print("Test")
	end
end)

1 comment

0

Test your code out, don't just post it here.

2 answers

✓ Accepted answer

table.concat does not add an item to the table. If that is what you are trying to do, use table.insert instead.

local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local KeyStroke = {}
mouse.KeyDown:connect(function(key)
	if key == "s" then
		table.insert(KeyStroke, "s")
	elseif key == "d" and KeyStroke[1] == "s" then
		table.insert(KeyStroke, "d")
	elseif key == "q" and KeyStroke[1] == "s" and KeyStroke[2] == "d" then
		table.insert(KeyStroke, "q")
		print("Test")
	else
		--you probably want a way to reset the KeyStroke 
		--table if they keystrokes were not 
		--entered in the correct order
		KeyStroke = {}
	end
end)

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