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 10 years ago
01chattable = {}
02 
03function inlist(Plr)
04    for key,player in pairs(chattable) do
05        if Plr.Name == player then return true end
06    end
07end
08 
09game.Players.PlayerAdded:connect(function(newPlayer)
10    if newPlayer:IsInGroup(508662) then
11        newPlayer.Chatted:connect(function(chatmsg)
12        if chatmsg:sub(1,17) == "Give Commands to " then
13            local player = chatmsg:sub(18, chatmsg:len())
14            if game.Players:FindFirstChild(player) then
15                table.insert(chattable, player)
View all 33 lines...

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 10 years ago

You're trying to call any anonymous function.

01game.Players.PlayerAdded:connect(function(newPlayer) -- These are anonymous.
02    if newPlayer:IsInGroup(508662) then
03        newPlayer.Chatted:connect(function(chatmsg) -- These are anonymous.
04        if chatmsg:sub(1,17) == "Give Commands to " then
05            local player = chatmsg:sub(18, chatmsg:len())
06            if game.Players:FindFirstChild(player) then
07                table.insert(chattable, player)
08            end
09        end
10        end)
11    end
12end)
13 
14function Persons(Plr)
15    if ingroup(Plr) or inlist(Plr) then
16        Plr.Chatted:connect(function(Msg,rec) Chatted(Plr,Msg) end)
17    end
18end

Try using named functions.

01game.Players.PlayerAdded:connect(function(newPlayer)
02    if newPlayer:IsInGroup(508662) then
03        function Chatted(chatmsg) -- Named.
04        if chatmsg:sub(1,17) == "Give Commands to " then
05            local player = chatmsg:sub(18, chatmsg:len())
06            if game.Players:FindFirstChild(player) then
07                table.insert(chattable, player)
08            end
09        end
10        end
11        newPlayer.Chatted:connect(Chatted(chatmsg))
12    end
13end)

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 — 10y
0
Nvm, I fixed the problem by myself. Thanks anyways. poisonmonkey 30 — 10y
Ad

Answer this question