01 | chattable = { } |
02 |
03 | function inlist(Plr) |
04 | for key,player in pairs (chattable) do |
05 | if Plr.Name = = player then return true end |
06 | end |
07 | end |
08 |
09 | game.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) |
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.)
You're trying to call any anonymous function.
01 | game.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 |
12 | end ) |
13 |
14 | function Persons(Plr) |
15 | if ingroup(Plr) or inlist(Plr) then |
16 | Plr.Chatted:connect( function (Msg,rec) Chatted(Plr,Msg) end ) |
17 | end |
18 | end |
Try using named functions.
01 | game.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 |
13 | 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