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

Can you make an argument index go to a specific point to further on?

I am making a :warn command but to have their own custom message. here is how it goes.

local RS = game:GetService('Replicated Storage')
local event = RS:WaitForChild('Event')

function onWarn(warn)
	local args = warn:split(' ')
	if args[1] == ':warn' then
		local plrToWarn = game.Players:FindFirstChild(args[2])
		if plrToWarn then
			local warnReason = args[3] -- How to i make it like args[3 to when input ends]
		end
	end
end

Dont worry about the Client bit that bit works its just the local warnReason im stuck on. It works as in this for example

:warn player You have been banned

Shows to Client You have been warned Reason: You

1 answer

✓ Accepted answer

The user's input would end at the length of the string, #args[3]. Since args[3] is the last argument in the command, the position of #args[3] is equal to the position of the length of the actual message itself, #warn, which is the last character in the string.

An easy way to check on this would be something similar to:

if #args[3] > 0 and args[3]:find(#args[3]) == warn:find(#warn) then

This tells the compiler to check if the argument exists, and if it does exist, check if the last character of the argument is the same as the last character of the entire string.

Now, in order to retrieve the 3rd argument and include it in the reason, the 3rd argument would be between the 2nd argument (args[2]) and the end of the string (#warn). I'm pretty sure you can figure this one out on your own.

1 comment

0

ok lemme try

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