Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to check if a textbox is equal to a child of Players?

Just a quick question, Is there a way to check if text is equal to a player. I'm trying to do something like:

script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.TextBox.Text == "/kill "..a and a = game.Players:GetChildren() then
script.Parent.Parent.TextBox.Text = a.." Killed"
end)

But it doesn't work. Any help is appreciated.

1 answer

✓ Accepted answer

###Yes you can. You would be using the string.sub function.

ROBLOX's explanation on that function:

#####Returns the substring of s that starts at i and continues until j; i and j may be negative. If j is absent, then it is assumed to be equal to the length of s. In particular, the call string.sub(s,1,j) returns s until as many characters as j, and string.sub(s, -i) returns a suffix of s with length i.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local textbox = script.Parent.Parent.TextBox

script.Parent.MouseButton1Click:Connect(function()
    for _, v in pairs(Players:GetPlayers()) do 
        -- loop through players, check if their name is any text after "/kill "
    
        if textbox.Text:sub(7):lower() == v.Name:lower() then 
           -- if their name is whats after "/kill "
           -- code 
        end
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.