TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jun 2015 11:20 AM |
for some odd readon I can't get this to work right..can you show me what I'm doing wrong?
if not _G.plrs[plr] then print(plr) table.insert(_G.plrs,plr) end
Output: > Player1 Player1 Player1
The event fires when I click a TextButton and keeps printing even if there is already an object in it..do tables already prevent duplicates? |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jun 2015 11:21 AM |
matchset.OnServerEvent:connect(function(plr) if not _G.plrs[plr] then print(plr) table.insert(_G.plrs,plr) end end) |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jun 2015 11:35 AM |
Ah. Simple fix.
matchset.OnServerEvent:connect(function(plr) if #_G.plrs > 0 then for i, v in next, (_G.plrs) do if not plr.Name == v then table.insert(_G.plrs,plr) else print("Already in table") end end else table.insert(_G.plrs,plr) end end) |
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 17 Jun 2015 11:35 AM |
function findfromtable(t,val) for _,v in pairs(t) do if v == val then return true end end return false -- idk is it needed ive always put it there end
if not findfromtable(_G.plrs,plr) then
end
|
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 17 Jun 2015 11:36 AM |
wow u ninjad me urself
ok i was slow i understand |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 17 Jun 2015 11:48 AM |
Change it to a hash table (dictionary) instead of an array. Instead of table.insert(_G.players, player) Use _G.players[player] = true
Hash tables have an average-case lookup and insertion complexity of O(1). |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jun 2015 12:05 PM |
This is the error I get when I try that:
13:01:40.294 - keys must be strings
--server script function matches.OnServerInvoke() return _G.plrs end
matchset.OnServerEvent:connect(function(plr) if #_G.plrs > 0 then for i, v in next, (_G.plrs) do if plr.Name ~= v then --workspace.Bool.Value = true --table.insert(_G.plrs,plr) _G.plrs[plr] = true else workspace.Bool.Value = false print(plr.Name) print("Already in table") end end else --workspace.Bool.Value = true --table.insert(_G.plrs,plr) _G.plrs[plr] = true end end)
--local script local plrs = matches:InvokeServer() --error
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jun 2015 12:11 PM |
lol wtf now my game is crashing when i use this code:
--server script
_G.plrs = game.Players:GetPlayers()
function matches.OnServerInvoke() return _G.plrs end
matchset.OnServerEvent:connect(function(plr) if #_G.plrs > 0 then for i, v in next, (_G.plrs) do if plr.Name ~= v then table.insert(_G.plrs,plr) else print(plr.Name) --started crashing when i added this i think? print("Already in table") end end else table.insert(_G.plrs,plr) end end)
--local script while wait(1) do local plrs = matches:InvokeServer() loadPlrs(plrs) end |
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 17 Jun 2015 12:12 PM |
wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com wiki.roblox.com
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jun 2015 12:13 PM |
| @iiEssence You're an idiot. |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 17 Jun 2015 12:14 PM |
| http://wiki.roblox.com/index.php?title=Basic_math |
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 17 Jun 2015 12:15 PM |
OHH IM SORRY
http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting
|
|
|
| Report Abuse |
|
|
|
| 17 Jun 2015 12:17 PM |
http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting
|
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|