generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Any Reason Why This Doesn't Work?

Previous Thread :: Next Thread 
PlusJon is not online. PlusJon
Joined: 27 Sep 2012
Total Posts: 1522
12 Nov 2012 04:55 PM
plrs = { }

game.Players.PlayerAdded:connect(function(p)
add = true
for _,v in pairs(plrs) do
if v.Name == p.Name then
add = false
break
end
end
if add then
table.insert(plrs, p.Name)
workspace.uniquePlayers.Value = workspace.uniquePlayers.Value +1
end
end)


It doesn't catch duplicate names...It just sort of skips the whole check.

I've tested this in both online servers, and offline servers.
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
12 Nov 2012 04:56 PM
Is there something in the output?
Report Abuse
PlusJon is not online. PlusJon
Joined: 27 Sep 2012
Total Posts: 1522
12 Nov 2012 04:58 PM
Nope.
Report Abuse
PlusJon is not online. PlusJon
Joined: 27 Sep 2012
Total Posts: 1522
12 Nov 2012 04:59 PM
The problem is it works, but doesn't work correctly. Which it should.
Report Abuse
PlusJon is not online. PlusJon
Joined: 27 Sep 2012
Total Posts: 1522
12 Nov 2012 05:03 PM
Nevermind. I forgot the '#' in the for do part.
Report Abuse
PlusJon is not online. PlusJon
Joined: 27 Sep 2012
Total Posts: 1522
12 Nov 2012 05:04 PM
NVM again. T_T

I'm tired. :L
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
12 Nov 2012 05:04 PM
Try
if add == false then

It probably won't work, but in there I can't see anywhere that you insert the name into the table...
Report Abuse
PlusJon is not online. PlusJon
Joined: 27 Sep 2012
Total Posts: 1522
12 Nov 2012 05:09 PM
plrs = { }

game.Players.PlayerAdded:connect(function(p)
  add = true
  -- Make it new by default
  for _,v in pairs(plrs) do
  -- Start the scan
    if v.Name == p.Name then
    -- does the name exist in the table yet
      add = false
      -- we found it does so set it to false so it doesn't add it
      break
      -- stop checking
    end
  end
  if add then
  -- if add is STILL true, which SHOULD be made false when duplicate name is found
    table.insert(plrs, p.Name)
    -- add the name to the table
    workspace.uniquePlayers.Value = workspace.uniquePlayers.Value +1
    -- increase the value
  end
end)
Report Abuse
PlusJon is not online. PlusJon
Joined: 27 Sep 2012
Total Posts: 1522
12 Nov 2012 05:12 PM
"if v.Name == p.Name then"

*facedesk*

I failed. Lol.
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
12 Nov 2012 05:12 PM
plrs = { }


game.Players.PlayerAdded:connect(function(p)
add = true
for _,v in pairs(plrs) do
if v.Name == p.Name then
add = false
return
--break breaks the loop
end
end
if add then
table.insert(plrs, p.Name)
workspace.uniquePlayers.Value = workspace.uniquePlayers.Value + 1
end
end)


~ thedeathmaster01 ~
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
12 Nov 2012 05:13 PM
lol

~ thedeathmaster01 ~
Report Abuse
TheAwesomenessDude is not online. TheAwesomenessDude
Joined: 17 Jul 2011
Total Posts: 11602
12 Nov 2012 05:13 PM
Maybe add needs to become false again at the end now that the name is found?
Report Abuse
PlusJon is not online. PlusJon
Joined: 27 Sep 2012
Total Posts: 1522
12 Nov 2012 05:16 PM
@Thedeathmaster

Why wouldn't I break the loop if the name was found? Why keep looking?

Return is useless in this case.

@TheAwesomeDude

No, that's not a problem.


@All
I fixed it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image