Admin Command Script not working

Yes, Let’s just focus on the code which is why I created this topic.

Alright, that’s good to hear. :smiley:
Mind sharing your script with the newly edits please? It’d be good to know where we are right now.

1 Like
local Prefix = "!";
local function GetPlayer(Message)

if (Message:sub(1, #Prefix) == Prefix) then
    Message = Message:sub(1 + #Prefix); -- Get the message after the prefix
    
    if (Message:sub(1, 5):lower() == "kill ") then -- Check if a player chatted "kill "
        local Target = GetPlayer(Message:sub(6)); -- Attempt to get the player
        
        if (Target ~= nil) then -- Do we have the player?
            Target.Character.Humanoid.Health = 0; -- Kill the player
        end
    end
end

Oof, seems we’re starting to get confused. Lemme lay out how the script would look.

local Prefix = "!" -- Command prefix
local Admins = {
	["TheeDeathCaster"] = true,
	["TrackoTheTaco"] = true,
	["Other Admin"] = true
} -- Dictionary of admin names

local function GetPlayer(Message) -- Get player method
	-- GetPlayer code
end

game.Players.PlayerAdded:Connect(function(Player) -- Listen for a new player
	Player.Chatted:Connect(function(Message) -- Listen for when a player chats
		if Message:sub(1, #Prefix) == Prefix and Admins[Player.Name] then -- Did they chat the prefix? And is the player an admin?
			Message = Message:sub(1 + #Prefix) -- Get the characters after the prefix
			
			if Message:sub(1, 5):lower() == "kill " then -- Did a player chat "kill "?
				local Target = GetPlayer(Message:sub(6)) -- Attempt to get target player
				
				if Target then -- Did we get the player?
					Target.Character.Humanoid.Health = 0 -- Kill the player
				end
			end
		end
	end)
end)

This is how the script would look. Please lemme know if you have any more questions. :slight_smile:

1 Like

It does not know who is admin so the script doesn’t know who can use that command.

That’s quite simple to accomplish, I’ll edit my post real quick and update it in a few minutes. :slight_smile:

EDIT
Alright, I made the change; added an Admins list, and a check if they’re in the list. This can be seen on lines 2 and 14.

1 Like

Sorry you just edited a message so I didn’t get a notification. Sorry for the late reply, I will try the new code.

1 Like

Hmm, Strange because it did not work and nothing came in the output. I might just close this and just use a pre-made admin command model.

Maybe just start over, this youtube link can help you make admin commands

1 Like

Im sure the problem lies here.

if Msg:sub(1,5) == "kill " or Msg:sub(1,5) == "Kill " then --Instead of 6, change it to 5

Also this

local Target = Players:FindFirstChild(Msg:sub(6)) --Instead of 7, change it to 6