So I have 2 scripts and I am trying to use a big global table. For some odd reason it won't work. Console says theres an error on line 12 however the script editor underlines the [] Heres the global table:
_G.Admins = { ["conman0552"] }
For some reason it also doesn't like my [] either
My script I want to use it with:
local isAdmin = _G.Admins function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end function onChatted(message, player) if message == "Close" and isAdmin[player.Name] then --change ":normal" to the name of the command game.Lighting.Door.Parent = game.Workspace end --copy everything from 'if message == ":norma;"' until the first 'end' and paste it between this and the 'end' below this. end --Copy and paste everything from if message == until the first 'end' and change the building name and command each time. game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end)
and
local isAdmin = _G.Admins function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end function onChatted(message, player) if message == "Open" and isAdmin[player.Name] then --change ":normal" to the name of the command game.Workspace.Door.Parent = game.Lighting end --copy everything from 'if message == ":norma;"' until the first 'end' and paste it between this and the 'end' below this. end --Copy and paste everything from if message == until the first 'end' and change the building name and command each time. game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end)
On both the door scripts the error is on line 12
The reason it's causing an error is because you told the script to check the _G.Admin table in the position of "player.Name". Basically, the table is looking for a key which doesn't exist.
What you should do is do a for loop through the table, and see if the child is an admin, like so:
local isAdmin = _G.Admins function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end function onChatted(message, player) if message == "Close" then for i, v in pairs (isAdmin) do if v == player.Name then -- You really should use the IDs like everyone said.. game.Lighting.Door.Parent = game.Workspace break end end end --copy everything from 'if message == ":norma;"' until the first 'end' and paste it between this and the 'end' below this. end --Copy and paste everything from if message == until the first 'end' and change the building name and command each time. game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end)
And you would do the same for the other script, though once again I'm not sure why you don't just put them in the same script. Hope this helped!
EDIT: Also, in your first one, those brackets are not necessary:
_G.Admins = { "conman0552", }
Should work fine.
EDIT 2: Whenever you see this.. where is your global table? You need one LocalScript copy and one Script copy of it. Also,
function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end function onChatted(message, player) if message == "Close" then for i, v in pairs (_G.Admins) do if v == player.Name then -- You really should use the IDs like everyone said.. game.Lighting.Door.Parent = game.Workspace break end end elseif message == "Open" then for i, v in pairs (_G.Admins) do if v == player.Name then game.Workspace.Door.Parent = game.Lighting break end end end end game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end)
You have a syntax error. You use []
for dictionaries (tables where each index has a value set to it). Example:
local Dictionary = { ["A"] = 1, ["B"] = 2, ["C"] = 3 } print(Dictionary["B"]) --> 2
For more information on Dictionaries, read this.
For your admin list, you'll have to use a normal table. This means just use string values with names in them.
_G.Admins = { "conman0552" }
One cause I could think of is that they both may not be scripts. One may be a normal script, and the other a local script. I'm not sure what the problem is. Have you tried using your "Developer Console" to see if it can indicate an issue?
Here are some links that may help you fix your problem:
http://wiki.roblox.com/index.php?title=Global_function http://wiki.roblox.com/index.php?title=Developer_console