Keyboard spam generator

So, yesterday I made a keyboard spam generator, and now that I finally got access to the DevForum, I’d like you guys to review it.
What this does is that when you press a button, it uses a for loop that selects a random character from a very long string of keyboard spam and concatenates that character with all the other text, and it does so 25 times, and it displays the keyboard spam onto a screen. (Also, I should probably mention that it displays the text onto the screen the whole time, and the script has a wait(0) inside the for loop so it basically looks like a dialog on one of those story games)
Anyways, here’s the code:

local result = script.Parent.res
local basetext = "cmgu45jtutgnb8u5hjyg87bg874g5j8 h45t4387gv45r8tuh438fj4wd3u28ru9w80erewuy9ahriuewhfdo4ewuhfwg43h9tr03hgwerj94ew56k5490r89gv 45 u465 b8943u trf43entoirnt  ujrenyg45erjgijmjeig,vfdigukdf7resjgfa9ewjtra7wgjbre87 by4me764 b5764e5 ht7y4e4th43a76ewth376hgfewy8rh3876hr238u487r3wjfudh87r h7ey4rm76432 6tre87e857j387t28t5ji45wu6hwo5tk4tpwtaw0rtj45re"
local length = 25 -- set this to whatever you want the length to be
generator = script.Parent.gen
generator.Touched:Connect(function()
	result.SurfaceGui.TextLabel.Text = ""
	wait(0)
	for i = 1, length do
		local rand = math.random(1, #basetext)
		local String = basetext:sub(rand, rand)
		result.SurfaceGui.TextLabel.Text = result.SurfaceGui.TextLabel.Text .. String
		wait(0)
	end
end)

(I also only have 1 month of scripting experience so if you find something wrong on it, please let me know!)
It works fine though, (I’ve tested it multiple times) so I am also gonna assume this is the simplest way to write a script that does this.
Edit: I forgot to include the .rbxl file!
test4-1.rbxl (52.4 KB)

2 Likes

Is there a reason you use a super-long string of garbage text and not just “0123456789 abc[…]xyz”? The end result is the same, you just need to have any character you want to be part of the “spam” present in the basetext string.

For the sake of Roblox, you will also probably want a system to make sure your random text generator doesn’t output inappropriate content. However unlikely it is, the script you’ve got now is technically capable of producing bad words and showing them to users. You can run the output string through the Roblox text filter to make sure it complies with the rules for the person it’s being shown to, and if you don’t want filtered text in your output, you can actually check to see if it’s filtered before displaying it.

This was not meant to be for a game or anything, I just made this for a test to improve my scripting skills and y’know… Not actually making a game or anything.
If i’d want an actual thing like this in a game, I’d actually bother into putting a filter onto it.
Also, the other point you made, there was actually a reason I used keyboard spam instead of the 123…abc …xyz thing. When a 7-year-old slams their keyboard to make a Roblox account, they usually use the letter “h”, “j” and “t” much more commonly than the letters “a”, “q” and “p”. So, I wanted to replicate that. And that’s the reason I used that. I know this isn’t really a reason per se, but that’s what I came up with.

1 Like

Use user input service as the result,because the typing is by userinput service

The player really has nothing to write, they just press a button and that’s it, so I don’t really think UserInputService helps much here

Your one is typing right???u definitely need to use userinput.U type the keys and a code will appeae right,that is youe objective right

I see u are using a button to actiavte it.that wont suffice because it would not be nice

Why though, what this was meant to be is that someone presses a button and then the generator generates keyboard spam, not the other way around