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

Trying to use String Pattern in an admin script?

It's my first time ever trying String patterns and i'm getting really confused on how to use them in my admin script command. What I want to be able to do is be able to say '/e clone/player/number' then the command would clone the player as many times as it says after the slash. But at the moment i've only got the findplayer part and find the slash. Please could someone help.


local isAdmin = {[14946581] = true, [122532233] = true, [17008190] = true}

function findPlayer(name)
    for _,v in pairs(game.Players:GetChildren()) do
        if string.lower(string.sub(v.Name, 1, #name)) == string.lower(name) then
            return v
        end
    end
end


function onChatted(message, player)
	pattern = '/'
    if message:sub(1, 9):lower() == ("/e clone/"):lower()and isAdmin[player.UserId] then
	victim = findPlayer(message:sub(10))
	if victim and victim.Character then
		message:sub(10):find(pattern)
		
		
		end
	end
end

Thank you.

3 comments

0

Isint that what it was supposed to do..?

0

No, I want to be able to enter a number after the slash so then my script loops that amount of times.

0

local num_times = message:match("%d+$") -- All numbers at the end of your string until the slash.

1 answer

✓ Accepted answer

you seem to be having a ton of commands for your script so I would try and you just do else if cmd == "" then

This code finds all slashes and then gets the text between them. After that it makes sure it starts with /e and then gets the text after that for the command.

local t={}
for location in string.find(message, "/") do
    table.insert(t, location)
end
local tabl = {}
for i = 1, #t- 1 do
	table.insert(tabl, message:sub(tabl[i] + 1, tabl[i + 1]))
end
if string.sub(tabl[1], 1, 2) == "e " then
	local cmd = string.sub(tabl[1], 3, #tabl[1])
	if cmd == "clone" and tonumber tabl[3] then
		local plr = getPlr(tabl[2])
		local num = tonumber(tabl[3])
		for i = 1, num do
			plr.Character:clone().Parent = workspace
		end
	end
end

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