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

A chatted that inserts players' names into a table isn't working?

I'm making a new command for my admin.

when i tested out this ;admin command, it didn't work. (i did it on someone who wasn't in the admins table)

admins = {"Player", "dragonmaster4111"}

function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end

game.Players.PlayerAdded:connect(function(plr)
	for i,v in pairs(admins) do
		if v == plr.Name then
			plr.Chatted:connect(function(msg)
				if msg:sub(1,6) == ";admin" then
					adm = findPlayer(msg:sub(8))
					if adm and adm.Character then
						table.insert(admins, 3, adm)
					end
				end
			end)
		end
	end
end)

1 comment

0

you were inserting adm into the table, which is an object. To fix it, on line 6 do return player.Name instead of return player

1 answer

✓ Accepted answer

While I inspect your original code, here's what I did:

Finished Script:

local admins = {"Player", "Player 1", "dragonmaster4111", "aquathorn321"}

local function findPlayer(player)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name == player then
return v
end
end
return false
end

game.Players.PlayerAdded:connect(function(player)
for i,v in pairs(admins) do
if v == player.Name then
player.Chatted:connect(function(msg)
if string.lower(string.sub(msg,1,6)) == ";admin" then
local adm = findPlayer(string.sub(msg,8))
if adm then
table.insert(admins,#admins + 1,adm.Name))
end
end
end)
break
end
end
end)

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