local player = string.sub(CommandBox.Text, v:len() +2 , CommandBox.Text:len())
print(player)
if CommandBox.Text == v .. " " .. game:GetService("Players"):FindFirstChild(player) then
17:13:06.912 Players.coolman21627.PlayerGui.Console.Console.Frame.Core:9: attempt to concatenate string with Instance - Client - Core:9
The error says everything you should know: it looks like you’re trying to add a string with an Instance, in this case a Player. You should get the player’s name and then add it to the string.
This should work:
local player = string.sub(CommandBox.Text, v:len() +2 , CommandBox.Text:len())
print(player)
if CommandBox.Text == v .. " " .. game:GetService("Players"):FindFirstChild(player).Name then
However, it’s still bad logic. What if the script finds no player? It’ll throw an error because you’re trying to get the name of a player that doesn’t exist. This is the better solution:
local playerNameFromUI = string.sub(CommandBox.Text, v:len() +2 , CommandBox.Text:len())
local player = game:GetService("Players"):FindFirstChild(playerNameFromUI)
if(player) {
if CommandBox.Text == (v .. " " .. player.Name) then
--Code
end
} else {
print("Player wasn't found!")
}
No, that means your script isn’t finding the player. Maybe you’re not getting the correct name of the player from the UI. This error shouldn’t occur with my second version of the script, try using that one.
local playerNameFromUI = string.sub(CommandBox.Text, v:len() +2 , CommandBox.Text:len())
local player = game:GetService("Players"):FindFirstChild(playerNameFromUI)
if(player) then
if CommandBox.Text == (v .. " " .. player.Name) then
--Code
end
else
print("Player wasn't found!")
end
Yeah, you have to put whatever you wanted to do in the second if block. The script does nothing on its own because you never told us what you want to do after checking that the command box is equal to the string with the player’s name. Just replace the --Code with whatever you were trying to do.
local CommandBox = script.Parent.CommandBox
local commands = require(script:WaitForChild("Commands"))
CommandBox:GetPropertyChangedSignal("Text"):Connect(function()
for _, v in pairs(commands.Commands) do
if CommandBox.Text ~= v then
if CommandBox.Text == v .. " --detect name here" then
CommandBox.TextColor3 = Color3.fromRGB(255,255,255)
else
CommandBox.TextColor3 = Color3.fromRGB(255,0,0)
end
else
CommandBox.TextColor3 = Color3.fromRGB(255,255,255)
end
end
end)