Why does my code only take in values

Basically I have an admin script that makes a console. And I have a line of code that defines the value of the command. But for some reason it only takes in numbers and not letters

local Value = string.match(Text, "(%d+)")
game.ReplicatedStorage.events.adminbricks.command:FireServer("kick", Value)

And when it picks up this value. And I run the command in the game. I get the error message


Also id like to add this is the line of code responsible for kicking the player:


Help would be appreciated!

1 Like

%d+ is the RegEx (regular expression) equivalent for searching digits with repetitions. .+ is the notation for all characters and probably what you need.


“Value” might be nil or different than what it’s supposed to be, can you print(Value) and post what the console outputs?


Are “kick” and “selfcicim” different prints or are they both “Value”?

They are both on the same value.

That seems to be the problem.


will be equivalent to:

game:GetService("Players"):FindFirstChild("kick selfcicim"):Kick()

In this case, game:GetService("Players"):FindFirstChild("kick selfcicim") will return nil. To avoid this, Value should only contain the username of the player being kicked, so Value should be selfcicim and that’s it.

1 Like

How do I make the value only selfcicim?

Well, I’d have to see the code that modifies the Value variable to give you a concrete answer.

elseif Text:find(string.lower("kick")) then
		local Value = string.match(Text, "(.+)")
		game.ReplicatedStorage.events.adminbricks.command:FireServer("kick", Value)

Can you print Text? That should be all I need to give you the answer you need after.

Side note: Text:find(string.lower("kick")) can be changed to Text:find("kick") since “kick” is already lowercase.

Its the same thing thats on the server earlier.

just use

local Args =string.split(Text," ") 
local command = args[0]
local user = args[1]

Here is my code: repeat wait() until game.Players.LocalPlayer script.Parent.FocusLost:connect(function()pcall(function() game.Players[tonumber(script.Parent.Text)]:Kick() end) end)

local Value = string.match(Text, "(.+)")

changed to:

local Value = string.split(Text, " ")[2]

This should be the fix. Basically splitting Text into two parts by using space as the separator would give you 2 elements: The command (1) and the username of the player (2).

1 Like

please igonore my previous code

local Value = string.match(Text, "(%w+)")
if Value then
    local playerToKick = game:GetService("Players"):FindFirstChild(Value)
    if playerToKick then
        -- Handle the case where the player is not found
        print("Player not found")
    -- Handle the case where no alphanumeric characters are found in Text
    print("Invalid input")

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