Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

help with string manipulation?

Asked by 5 years ago
Edited 5 years ago

i dont focus that much on string manipulation, but I want to make a kick command though when i was testing around with string.sub it doesnt work for some reason:

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        if message == string.sub(":kick ", 1, 6) then
            print("lol")
        end
    end)
end)

im not asking for a script of a entire kick command, but i just want a idea of it

1 answer

Log in to vote
1
Answered by
SmartNode 383 Moderation Voter
5 years ago
Edited 5 years ago

You should definitely use:

string.match(a1, a2)

This will definitely give you the results you need.

Example:

if string.match(message, ":kick ") then

    print('Someone was kicked')

    if game.Players:FindFirstChild(message:gsub(":kick ", '')) then

        game.Players:FindFirstChild(message:gsub(":kick ", '')):Kick()

        print(game.Players:FindFirstChild(message:gsub(":kick ", '')).Name..' was kicked')

    end

end

Why?

If it does contain that message, then it returns true, if it doesn't- return false.

a1 = string/target

a2 = string to find in target

0
what is gsub User#23365 30 — 5y
0
:gsub - arg1 = the message, arg2 = the text to look for inside of the message, arg3 the string to replace the text with SmartNode 383 — 5y
Ad

Answer this question