Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
awfulszn 394 Moderation Voter
7 years ago
Edited 6 years ago

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)
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. AZDev 590 — 7y
0
That's not the problem... awfulszn 394 — 7y
0
They don't appear to be set up like that though..? Could you be more specific and clarify about what you're asking? TheeDeathCaster 2368 — 7y
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. awfulszn 394 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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.

Ad

Answer this question