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

How do I split the parts of an admin command up?

Asked by 5 years ago

Hello, I have been working on an admin script. However, on this message command. I can not get the script to split up the command, player and message do three separate variables.

After looking at: https://developer.roblox.com/articles/string-patterns-reference I got closer to fixing the problem

However, the script only set the message variable to the first word of the command.

This is my code:

if string.find(msg:lower(), "!msg") then

    if msg:sub(1, 8):lower() == "!msg all" then
        local a,b,message = string.find(msg, "!msg all (%S+)") --> (%S+) only sets the variable message to the first word
        for i, player in pairs(game.Players:GetPlayers()) do
            if tostring(player.Name) ~= tostring(speaker) then

                MessagePlayer:FireClient(game.Players:FindFirstChild(player.Name), message)
            end
        end
    else

        local a,b,name,message = string.find(msg, "!msg (%S+) (%S+)")         --> (%S+) only sets the variable message to the first word
        local name2 = NameShortening(name)
        if name2 ~= nil then

            MessagePlayer:FireClient(name2, message)

        else

            TextService:FireClient(speaker, "This player does not exist!")
        end
    end
end

This is my issue:

local a,b,name,message = string.find(msg, "!msg (%S+) (%S+)")

As if the command was: !msg Tweakified Thank you for helping me.

The variable message would equal to 'Thank' not 'Thank you for helping me.'

Any help/advice that you can give me to fix this issue would be appreciated. Tweakified

0
I’m unable to find the problem with your script since the code formatting is broken for me specifically, but I do remember reading this tutorial that helped me separate parts of a command when I was trying to make admin commands: https://devforum.roblox.com/t/59691 User#20279 0 — 5y

Answer this question