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

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

Asked by 9 years ago

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)
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 aquathorn321 858 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

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)
Ad

Answer this question