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

Why aren't these keys getting added to the string? [SOLVED]

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)

1 answer

✓ Accepted answer

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

3 comments

0

I see that now... But it worked even with theString.byte(key) which doesn't make sense.

0

It worked because usually when you call byte as a method, you use a colon. You used a period and you passed it a parameter, so it worked normally.

0

Weird.

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