Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
|
| 25 Mar 2017 04:16 PM |
who touched a part?
ATR'er since 2013. |
|
|
| Report Abuse |
|
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 25 Mar 2017 04:23 PM |
Use :Disconnect to disconnect the event from the function simple's.
R$0 |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 25 Mar 2017 04:37 PM |
| ########################################## |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2017 04:37 PM |
wiki.roblox.com/?title=Table#Arrays
|
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 25 Mar 2017 05:07 PM |
local Test = {} table.insert(Test,"NOOB") print(Test[1])
R$0 |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 25 Mar 2017 05:11 PM |
What is (places) is that a variable or a array.
R$0 |
|
|
| Report Abuse |
|
|
Eventive
|
  |
| Joined: 28 Jul 2011 |
| Total Posts: 9827 |
|
| |
|
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 |
|
|
|
| 25 Mar 2017 05:13 PM |
Also what are you attempting to return lol.
R$0 |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 25 Mar 2017 05:14 PM |
ofcourse it would filter im not even gonna bother
|
|
|
| Report Abuse |
|
|