Im stuck with this script

So, hey, im doing an admin command system and just started, but i got kinda stuck:

im doing a teleport command, and i got stuck to detect if the values of the command message are correct, so i have 2 Module Scripts, 1 for handling all the commands, and other for the teleport command:
this modules are in ReplicatedStorage, this is the one who handles the commands:

local adminCmds = {}

local tpCmd = require(script.TeleportCmd)

function tp(plr, pos, addY, addPos)
	tpCmd.Teleport(plr, pos, addY, addPos)
end

return adminCmds

and this is the module for the teleport command:

local teleportCmd = {}

function teleportCmd.Teleport(plr, pos, addY, addPos)
	local char = plr.Character
	if char then
		if addY then
			char.HumanoidRootPart.CFrame = CFrame.new(pos) + Vector3.new(0, addPos, 0)
		else
			char:MoveTo(pos)
		end
	end
end

return teleportCmd

this script (a ServerScript in ServerScriptService) is the one who handles when the player sends the chat command:

local commandsModule = require(game.ReplicatedStorage.Modules.AdminCmds)

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		local loweredText = string.lower(msg)
		if string.find(loweredText, "/tp") then
			
		end
	end)
end)

but i got kinda stuck in here cause idk how to get the pos, the boolean, and the numberValue…

thanks!

1 Like

You can use string.split in order to split the message into different inputs divided by spaces. For example,

local msg = "/tp bobowawahaha 100,100,100"
local splitMsg = string.split(msg, " ")

local command = splitMsg[1] -- /tp
local input1 = splitMsg[2] -- bobowawahaha
local input2 = splitMsg[3] -- 100,100,100

From there, you can process it with the rest of your code.

so, the input2, would be, the position, or i didnt quite understand, cause i want to do a “/tp” then a Vector3 value, then a boolean, then a numberValue, sorry for the problems im kinda new to scripting hehe

Could you write out what your desired command would look like?

1 Like

Input2 would still be a string, you would need to convert it to a Vector3 in your processing. You can do this with string.split again, separating by the comma to get the X, Y, and Z values and create the Vector3 from that. Anything that is not a string would have to be processed in order to convert it into your desired data type from the input.

“/tp 10, 10 ,10, true, 3”


What’s the purpose of “true” and “3” in your command? If i were to write this I would probably make it look something like this:
“/tp [Player Name] 10 10 10” I wouldn’t use commas and instead use spaces. Now, using that information you should follow @bobowawahaha’s previous replies. Hope this helped.

so, hi, the “true” is a boolValue to check if i want to teleport the player x amount of studs in Y, and the “3” is the studs amout to move