Warn Command With Reason

Hello fine developers,

I’m currently making my own admin system, and I’ve just started out with a warn command. I’m currently using string.split with a space inbetween the quotes to split the player’s message. But of course, the reason which could be long would normally have spaces, so what would I do?

Here is the script (supposedly in a ModuleScript):

local adminCommands = {
	

	
	warnCommand = function(author, message)
		local player = game.Players:FindFirstChild(author);

		if player then
			local IsAdmin = player.Character:FindFirstChild("IsAdmin");
			if IsAdmin then
				if IsAdmin.Value == true then
					local rankCount = player.Character:FindFirstChild("Rank");
					if rankCount.Value >= configSettings.modCommands.Warn.Requirement then
						if message:sub(1, #";warn"):lower() == ";warn" then
							local args = message:split(" ")
							local playerToWarn = game.Players:FindFirstChild(args[2])
							if playerToWarn then
								local warnMessage = args[3] 
							end
						end
					end
				end
			end
		end
	end
}

The problem here is that I don’t know how I’ll join back the reason part into one string, or I don’t know how I"ll found out how long the words are which are split by a space.

This is currently what I’m trying to do:

:warn <player> <reason>
2 Likes

Just assume that everything after the player, i.e. the second space, is the warning message. You know the command, you know the player, so the second space (if it exists) occurs at

string.len(";warn " .. playerToWarn.Name)

You then use string.sub to get everything after that point, and that’s the message.

5 Likes

Looks like I haven’t been clearly thinking properly. Sorry, it’s just really hard to script when you randomly have a runny nose at random days, random times for no particular reason - thanks anyways.

((Yours works in case you think it doesn’t))

1 Like