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:
%d+ is the RegEx (regular expression) equivalent for searching digits with repetitions. .+ is the notation for all characters and probably what you need.
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.
elseif Text:find(string.lower("kick")) then
print("kick")
local Value = string.match(Text, "(.+)")
game.ReplicatedStorage.events.adminbricks.command:FireServer("kick", Value)
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)
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).
local Value = string.match(Text, "(%w+)")
if Value then
local playerToKick = game:GetService("Players"):FindFirstChild(Value)
if playerToKick then
playerToKick:Kick()
else
-- Handle the case where the player is not found
print("Player not found")
end
else
-- Handle the case where no alphanumeric characters are found in Text
print("Invalid input")
end