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

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

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

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)

3 comments

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.

0

I'm the one who asked the question.

0

Try looking before downvoting,

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