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

Admin commands I made won't work?

The error I am getting: 20:37:30.742 - Trying to call method on object of type: Players with incorrect arguments. My code is:

local Admins = {"OldBo5"} 
local Prefix = ":"
for v,i in ipairs(Admins) do
	game.Players(Admins)[i].Chatted:Connect(function(msg)
		if msg:lower() == Prefix .. "ff admins" then
			for v,i in pairs(game.Players[Admins]:GetChildren()) do
				local ff = Instance.new("ForceField")
				ff.Parent = i.Character
				ff.Name = "ForceField"
			end
			if msg:lower() == Prefix .. "kill admins" then
			for v,i in pairs(game.Players[Admins]:GetChildren()) do
				i.Character.Humanoid.Health = 0
			end
					if msg:lower() == Prefix .. "god admins" then
			for v,i in pairs(game.Players[Admins]:GetChildren()) do
				i.Character.Humanoid.MaxHealth = math.huge
				wait(1)
				i.Character.Humanoid.Health = math.huge
			end
					end
			if msg:lower() == Prefix .. "ungod admins" then
			for v,i in pairs(game.Players[Admins]:GetChildren()) do
				i.Character.Humanoid.MaxHealth = 100
				wait(1)
				i.Character.Humanoid.Health = 100
			end
			end
								if msg:lower() == Prefix .. "unff admins" then
			for v,i in pairs(game.Players[Admins]:GetChildren()) do
				local ff = i.Character:findFirstChild("ForceField")
				ff:Destroy()
			end
			end
			end
		end	
		end)
end

Please help!

2 answers

This checks if the Player's name is in the AdminList and sets 'IsAdmin' to true.

Local Script:

local Player = game.Players:FindFirstChild(game.Players.LocalPlayer.Name)
local Character = Player.Character

local AdminList = {"OldBo5", "Roblox"}
local IsAdmin = false 

function checkIfAdmin()
	for AL = 1, #AdminList do 
		for _, v in pairs(game.Players:GetChildren()) do 
			if v.Name == AdminList[AL] then 
				print("" .. v.Name .. " is an admin!")
				IsAdmin = true -- Enables this so the player has access to admin commands
			end
		end
	end
end

Player.Chatted:connect(function(msg)
	if IsAdmin then 
		-- Commands in here
	end
end)

2 comments

0

You can't fire "Chatted" event from the client.

0

My bad, never used Chatted for a very long time.

game.Players[Admins] is the error. I'm not sure how you came upon it? You can find a specific player with game.Players:FindFirstChild("Name Of Admin")

I would just scrap the whole thing and start with game.Players.PlayerAdded:Connect(function(Player) end) and you have too many for loops written one after another.

local Admins = {"OldBo5", "MooMooThalahlah"} 
local Prefix = ":"

local function CheckIfAdmin(player)
    local isAdmin = false

    for _,admin in pairs(Admins) do
        if player.Name == admin then
            isAdmin = true
        end
    end

    return isAdmin
end

local function GiveSpecialEffect(typeOfEffect)
    --Iterate through all admins
    for _,admin in pairs(Admins) do
		local adminPlayer = game.Players:FindFirstChild(admin)

		if adminPlayer then --Check if the player still exists in the game
		        if typeOfEffect == "Effect1" then
		            print(typeOfEffect)
		            --Do effect 1
		        elseif typeOfEffect == "Effect2" then
		            --Do effect 2 and so on
		        end
		end
    end
end

game.Players.PlayerAdded:Connect(function(Player) 
    if CheckIfAdmin(Player) then
        --Only check the chat if the admins are typing
        local Admin = Player --Not needed just easier for me to read

        Admin.Chatted:Connect(function(msg) 
            if msg:lower() == Prefix .. "special command" then
                GiveSpecialEffect("Effect1")
            end
        end)
    end
end)

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