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 » Scripters
Home Search
 

Re: How do you get the first, second, and third player

Previous Thread :: Next Thread 
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 04:16 PM
who touched a part?


ATR'er since 2013.
Report Abuse
SnowyKirby is online. SnowyKirby
Joined: 15 Jan 2013
Total Posts: 68009
25 Mar 2017 04:17 PM
table.insert


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 04:18 PM
Each time the part is touched, determine if the BasePart belongs to a player's character. If so (and if they don't already exist in the table), add them to the table. Otherwise, do nothing.

Once the table has 3 elements, disconnect the function from the event.


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 04:20 PM
So like this?


local places = {}

script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
table.insert(hit.Parent.Name, places)
---- How would I detect the amount then disconnect?
end
end)


ATR'er since 2013.
Report Abuse
QuantumNexsus is not online. QuantumNexsus
Joined: 09 Nov 2014
Total Posts: 2451
25 Mar 2017 04:23 PM
Use :Disconnect to disconnect the event from the function simple's.


R$0
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 04:24 PM
First of all, you're using table.insert incorrectly. Your current method will also allow players to occupy the table more than once. ############################################################# ################################################################
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 04:24 PM
First of all, you're using table.insert incorrectly. Your current method will also allow players to occupy the table more than once.

wiki.roblox.com/index.php?title=Operator#Miscellaneous
wiki.roblox.com/index.php?title=RBXScriptSignal#Methods_2


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 04:31 PM
How do I make it so they can't be added more than once?

local places = {}

function OnTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
table.insert()
end
end

if #places == 3 then
touched:Disconnect()
end
touched = script.Parent.Touched:connect(OnTouched)


ATR'er since 2013.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 04:32 PM
Iterate through the array and check if the player already exists as a value in the array.


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 04:35 PM
How do I iterate through a table to check for a name?

I know i,v in pairs() but then what?


ATR'er since 2013.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 04:37 PM
##########################################
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 04:37 PM
wiki.roblox.com/?title=Table#Arrays


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 04:40 PM
Like this? Btw thanks for being patient and helping me.


local places = {}

function OnTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
for i,v in ipairs(places) do
if v ~= hit.Parent.Name then
table.insert(hit.Parent.Name, places)
end
end
end
end

if #places == 3 then
touched:Disconnect()
end
touched = script.Parent.Touched:connect(OnTouched)


ATR'er since 2013.
Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 04:56 PM
bump


ATR'er since 2013.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 05:05 PM
No; forward declare `touched` so you can just disconnect it in the function that is connected to the event. Also, you're still using table.insert incorrectly.


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 05:05 PM
Can you give me an example of how to use table.insert?


ATR'er since 2013.
Report Abuse
QuantumNexsus is not online. QuantumNexsus
Joined: 09 Nov 2014
Total Posts: 2451
25 Mar 2017 05:07 PM
local Test = {}
table.insert(Test,"NOOB")
print(Test[1])



R$0
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
25 Mar 2017 05:08 PM
Do something like this:

for _, value in pairs(places) do
if player == value then -- Define `player` with the return value of GetPlayerFromCharacter
return -- The player already exists in the table; do nothing
end
end

table.insert(places, player) -- You switched the arguments around


Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 05:10 PM
function OnTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
for i,v in pairs(places) do
if hit.Parent.Name == v then
return
elseif hit.Parent.Name~= v then
table.insert(places, hit.Parent.Name)
end
end
end
end


ATR'er since 2013.
Report Abuse
QuantumNexsus is not online. QuantumNexsus
Joined: 09 Nov 2014
Total Posts: 2451
25 Mar 2017 05:11 PM
What is (places) is that a variable or a array.


R$0
Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 05:12 PM
array


ATR'er since 2013.
Report Abuse
Eventive is not online. Eventive
Joined: 28 Jul 2011
Total Posts: 9827
25 Mar 2017 05:12 PM
local places = {}
function OnTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
for i,v in pairs(places) do
if hit.Parent.Name == v then
return
elseif hit.Parent.Name~= v then
table.insert(places, hit.Parent.Name)

end
end
end
end


ATR'er since 2013.
Report Abuse
QuantumNexsus is not online. QuantumNexsus
Joined: 09 Nov 2014
Total Posts: 2451
25 Mar 2017 05:13 PM
Also what are you attempting to return lol.


R$0
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
25 Mar 2017 05:14 PM
local playersTouched = {} local function playerAlreadyTouched(player) for i,v in pairs(playersTouched) do if v == player then return true end end end script.Parent.Touched:connect(function(hit) local player = game.Players:FindFirstChild(hit.Parent.Name) if player and ################ ## ########## and #playersTouched < 3 then table.insert(playersTouched,player) print(player.Name,"has touched the brick! Place:",#playersTouched) if #playersTouched >= 3 then print("The race has ended!") end end end)
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
25 Mar 2017 05:14 PM
ofcourse it would filter im not even gonna bother


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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