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

Problems with giving access to commands?

Asked by 9 years ago
chattable = {}

function inlist(Plr)
    for key,player in pairs(chattable) do
        if Plr.Name == player then return true end
    end
end

game.Players.PlayerAdded:connect(function(newPlayer)
    if newPlayer:IsInGroup(508662) then 
        newPlayer.Chatted:connect(function(chatmsg)
        if chatmsg:sub(1,17) == "Give Commands to " then 
            local player = chatmsg:sub(18, chatmsg:len())
            if game.Players:FindFirstChild(player) then
                table.insert(chattable, player)
            end
        end 
        end)
    end
end)

function Persons(Plr)
    if ingroup(Plr) or inlist(Plr) then
        Plr.Chatted:connect(function(Msg,rec) Chatted(Plr,Msg) end)
    end
end

game.Players.PlayerAdded:connect(Persons)

Plr = game.Players:GetChildren()
for i = 1,#Plr do
    Persons(Plr[i])
end 

The first function shows the part where it checks to see if a person's name is in the chattable. The second function shows the part where admins can add people to this chattable list. The only problem is: it's not working. I'm pretty sure I called it correctly in the last function, but I may be wrong. Can someone help me and explain to me why this doesn't work? Thanks. (By the way, ignore the ingroup(Plr) part. It doesn't relate to this issue.)

1 answer

Log in to vote
1
Answered by 9 years ago

You're trying to call any anonymous function.

game.Players.PlayerAdded:connect(function(newPlayer) -- These are anonymous.
    if newPlayer:IsInGroup(508662) then 
        newPlayer.Chatted:connect(function(chatmsg) -- These are anonymous.
        if chatmsg:sub(1,17) == "Give Commands to " then 
            local player = chatmsg:sub(18, chatmsg:len())
            if game.Players:FindFirstChild(player) then
                table.insert(chattable, player)
            end
        end 
        end)
    end
end)

function Persons(Plr)
    if ingroup(Plr) or inlist(Plr) then
        Plr.Chatted:connect(function(Msg,rec) Chatted(Plr,Msg) end)
    end
end

Try using named functions.

game.Players.PlayerAdded:connect(function(newPlayer) 
    if newPlayer:IsInGroup(508662) then 
        function Chatted(chatmsg) -- Named.
        if chatmsg:sub(1,17) == "Give Commands to " then 
            local player = chatmsg:sub(18, chatmsg:len())
            if game.Players:FindFirstChild(player) then
                table.insert(chattable, player)
            end
        end 
        end
        newPlayer.Chatted:connect(Chatted(chatmsg))
    end
end)

There may be a syntax error, I was going quick. If you get any errors in the output, reply to me.

Also, give this a read, it should have information on anonymous functions. http://wiki.roblox.com/index.php?title=Function

0
There's an error with the chatmsg part on 11. It says, "Unknown global 'chatmsg'" poisonmonkey 30 — 9y
0
Nvm, I fixed the problem by myself. Thanks anyways. poisonmonkey 30 — 9y
Ad

Answer this question