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

Kill command won't work in my admin script? [Solved]

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

I have an admin script, and for some strange reason the kill command does not work.

local Admins = {["19498972"] = 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


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

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

-- Kill Command
function commandTable.kill(message, player)
    victim = findPlayer(message:sub(6))
        if victim and victim.Character then
            victim.Character:BreakJoints()
       end
end

game.Players.PlayerAdded:connect(function(player)
    if Admins[tostring(player.UserId)] then
        player.Chatted:connect(function(message) 
            if message:sub(1,1) == prefix then

                message = message:sub(2, #message)

                if commandTable[message] then
                    commandTable[message](message, player)
                end
            end
        end)
    end
end)

1 answer

Log in to vote
-1
Answered by
awfulszn 394 Moderation Voter
7 years ago

Fixed code;

local Admins = {["19498972"] = 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(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
Do not just post code: explain the reasoning behind your answer. What was wrong before? What did you do to fix it? What were the change(s)? Your answer is vague. TheeDeathCaster 2368 — 7y
0
I'm the one who asked the question. awfulszn 394 — 7y
0
Try looking before downvoting, awfulszn 394 — 7y
Ad

Answer this question