This has been solved. The solution was to use the KeyUp event instead of KeyDown.
Original Post:
What I want this to do is once you press /
, every time you press a key after that it will be added to a string variable called theString
, until you press Enter
and it resets. This works, but it will not record certain keys like numbers, i, and o. Is there any way to get around this?
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local addToString = false local theString = "" mouse.KeyDown:connect(function(key) if key == "/" and not addToString then addToString = true print("add to String is true") elseif theString.byte(key) == 13 and addToString then --13 = "Enter" print(theString) theString = "" addToString = false elseif theString.byte(key) ~= 13 and addToString then theString = theString..key print(key.." was added to the String") end end)
You were trying to call a function that doesn't exist. When manipulating strings, you use the string library or you use the methods like so.
theString.byte(key)
Should be
string.byte(key) -- using string library -- or key:byte() -- built in method