Getting player from command

For example, I have a command :speed me 100, it reads that there’s “me”, so it returns the player. But if I type :speed em 100, it still executes, and I don’t want it to. How can I fix this?

if args[2] then
		if args[2] == "me" then
			return {player}
		elseif args[2] == "all" then
			local players = {}
			for _,v in pairs (game.Players:GetPlayers()) do
				table.insert(players, v)
			end
			return players
		else
			for _,v in pairs(game:GetService("Players"):GetPlayers()) do
				if string.find(v.Name, args[2]) then
					return {v}
				end
			end
		end
	end
	return {player}

the one i’m highlighting with multiple dashes is probably the problem, when the if statement of the arg[2] thing ends, it still basically has that “return {player}” thing so even if the message didn’t require all the alternative requirements, it’ll still return the {player}, hopefully i helped so you must remove that

2 Likes
if args[2] then
		if args[2] == "me" then
			return {player}
		elseif args[2] == "all" then
			local players = {}
			for _,v in pairs (game.Players:GetPlayers()) do
				table.insert(players, v)
			end
			return players
		else
			for _,v in pairs(game:GetService("Players"):GetPlayers()) do
				if string.find(v.Name, args[2]) then
					return {v}
                else
                    warn("wrong input")
                    return nil
                end
			end
		end
	end

Shud fix it.

1 Like