Cannot figure out commands

Making a command that spawns pipebombs based on h ow many you put in. It will not work for the life of me

I don’t get errors in console because roblox dosen’t put anything in the console any more. Probably a bug

wait(1)

local Admins = {"Finger_Slinger","crolaa"}




local function GetPlayerByName(PlayerName)
	local ReturnPlayer
	for i,v in next, game:service"Players":GetPlayers() do
		if v.Name:lower():sub(1,#PlayerName):match(PlayerName:lower()) then
			ReturnPlayer = v
		end
	end
	return ReturnPlayer
end

local function GiveStand(Player,StandID)
	if not Player then return end

	for _ = 1, StandID do
		wait()
		local pipebomb = game.ReplicatedStorage.PipeBomb:Clone()
		pipebomb.Parent = Player.Character
		pipebomb.CFrame = Player.Character.Torso.CFrame * CFrame.new(0,0,0)

	end



end



game:service"Players".PlayerAdded:connect(function(player)
	local TradeDebounce = false
	player.Chatted:connect(function(msg)
		local Orig = msg
		local Words = {}
		local prefix = "/"
		if not msg:lower():sub(1,1):match(prefix:lower()) then return end
		local msg = msg:sub(2,#Orig)
		for word in string.gmatch(msg,"%S+") do
			table.insert(Words,word)
		end

		if Words[1] == "bubger" and Words[2] and Words[3] then
			if tonumber(Words[3]) and GetPlayerByName(Words[2]) then
				for i,v in next, Admins do
					if v == player.Name then
						local Target = GetPlayerByName(Words[2])
						local SID = tonumber(Words[3])
						GiveStand(Target,SID)
					end
				end
			end
		end
	end)
end)





halp

To check if its a command find the prefix at the start of the message

function Chatted(Message)
	local Prefix = "/"
	local HaxPrefix = Message:lower():sub(1,1):match(Prefix:lower()) == Prefix -- Returns boolean value
	
	if HaxPrefix then
		-- The message is a command
	end
end

Next we need to detect if the message is actually a command, and dosnt just have the prefix.

local Commands = {
	-- Make sure all command names are lower case
	["command"] = function(Player,Args)
		-- Run the command
	end,
}

function Chatted(Message)
	local Prefix = "/"
	local HaxPrefix = Message:lower():sub(1,1):match(Prefix:lower()) == Prefix -- Returns boolean value
	
	if HaxPrefix then
		local Args = Message:lower():sub(2,#Message):split(" ")
		
		if Commands[Args[1]:lower()] then
			Commands[Args[1]:lower()](game.Players.LocalPlayer)
		end
	end
end

Now we just need to add the arguments!

local Commands = {
	-- Make sure all command names are lower case
	["command"] = function(Player,Args)
		-- Run the command
	end,
}

function Chatted(Message)
	local Prefix = "/"
	local HaxPrefix = Message:lower():sub(1,1):match(Prefix:lower()) == Prefix -- Returns boolean value
	
	if HaxPrefix then
		local Args = Message:lower():sub(2,#Message):split(" ")
		
		if Commands[Args[1]:lower()] then
			local CommandArgs = {}
			for I,Arg in pairs(Args) do
				if I > 1 then
					table.insert(CommandArgs, Arg)
				end
			end
			
			Commands[Args[1]:lower()](game.Players.LocalPlayer, CommandArgs)
		end
	end
end

Done!
Now you just need to add the commands!

Example command

["kill"] = function(Player,Args)
		local ToKill = game.Players:FindFirstChild(Args[1])
		if ToKill then
			local Humanoid = ToKill.Character.Humanoid
			Humanoid.Health = 0
		end
	end

Hope this works! :grinning:

1 Like

Try and put some print statements after the functions are executed. (For example, before the return is sent.

Another thing, having the player making a “pipeBomb” could be classed as breaking the Roblox ToS (Term of Service) As it goes under, section 11:

(Highlighted Blue Section)

Sorry for the late response my friend. This is the best tutorial for this specific issue I’ve read. Keep it up homie.

Helped me solve my issue entirely!

1 Like