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

All admin commands require a player's name and I don't want some of them to?

Okay, I am making an admin script, but on commands, such as rejoin and reset it requires a players name, and I don't want them commands to have that. Only kick and kill should have it. i.e. ;kick mosski123

Here is my code;

local Admins = {
	["19498972"] = true, 
	["1540993"] = true, 
	["46641586"] = true
}

local prefix = ';' 

local commandTable = {}


function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end

function commandTable.reset(message, player)
    player.Character:BreakJoints()
end

function commandTable.rejoin(message, player)
	game:GetService("TeleportService"):Teleport(game.PlaceId, player)
		if player.Character ~= nil then
		player.Character:remove()
	end
end

function commandTable.kill(message, player)
	victim = findPlayer(message)
        if victim and victim.Character then
            victim.Character:BreakJoints()
       end
end

function commandTable.kick(message, player)
	victim = findPlayer(message)
		if victim and victim.Character then
			victim:Kick("[KICK]: "..player.Name.." has kicked you from the server.")
	end
end

game.Players.PlayerAdded:connect(function(player)
	if Admins[tostring(player.UserId)] then
		player.Chatted:Connect(function(message)
			local command, argument = message:match(prefix.."(.+) (.+)")
			if command and commandTable[command] then
				commandTable[command](argument, player)
			end
		end)
	end
end)

4 comments

0

You're only connecting the chatted event to admins. You should connect the chatted event to all and then check if the player is admin when specific commands are run.

0

That's not the problem...

0

They don't appear to be set up like that though..? Could you be more specific and clarify about what you're asking?

0

Basically, I have four commands, but they all require a target player to work. On the commands rejoin and reset, I want them to just be a command and only target the local player.

1 answer

✓ Accepted answer

I suggest you use String Manipulation. To be specific: string.sub(). What this done is it takes out a specificied section out of a string. This means that you can assign the player as a seperate variable by using string.sub().

For example, if you wanted to kill a player, do:

local target = string.sub(message, 6)

The above will take out anything said after ;kick or ;kill.

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