Cheat codes like

I want to make script that you can type on keyboard some words like in Gta San Andreas game. But i dont have any idea how to make achieve this.
Any thoughts?


Something like this.

2 Likes

You could do something like this:

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local joinedCodeString = ""
local lastCodeUpdate = nil
local player = Players.LocalPlayer

local cheatCodeTable = {
	["TESTCODE"] = function()
		print(player.Name, "executed TESTCODE")
	end,
	
	["ANOTHERCODE"] = function()
		print(player.Name, "executed ANOTHERCODE")
	end,
}

UserInputService.InputBegan:Connect(function(input: InputObject)
	if input.UserInputType ~= Enum.UserInputType.Keyboard then
		return
	end
	
	if not input.KeyCode then
		return
	end
	
	if input.KeyCode.Value < 97 or input.KeyCode.Value > 122 then -- Ignore characters that are not alphabets
		return
	end
	
	if lastCodeUpdate and (os.clock() - lastCodeUpdate) >= 2.5 then -- Time before cheat code resets
		joinedCodeString = ""
		lastCodeUpdate = nil
		return
	end

	joinedCodeString ..= input.KeyCode.Name
	lastCodeUpdate = os.clock()
	
	if not cheatCodeTable[joinedCodeString] then
		return
	end
	
	cheatCodeTable[joinedCodeString]()
	
	joinedCodeString = ""
	lastCodeUpdate = nil
end)

I think I didn’t understand at all, you want a textbox, in which players can type? Or you want the players to write a script to type?
Thanks @N1kAllj

I want to make when player something typing in keyboard. Like a command in chat but without it.

What mean input.KeyCode.Value < 97. Also i have an idea. What if I use multiple keycodes with UserinputService.

It will work with multiple keycodes. Just make a LocalScript in StarterPlayerScripts and paste in the script.

Ok thx for helping, I will try this.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.