I see. First we want to detect the player touching the brick. So we insert a script into the brick, and we write:
local list = {}
script.Parent.Touched:Connect(function(part)
end)
We added a list, any players that touch the part will be added to this list.
When the touch event occurs, it will fire the function with the parameter "part".
Next we confirm it's a player.
if part.Parent:FindFirstChild("Humanoid") then
end
This will confirm it's a player. It checks the part's parent, and if it finds the first child named "Humanoid" then it will return true. If it is a player then it will run the code after "then".
Now we add the player instance to the list.
list[#list+1] = game.Players:GetPlayerByCharacter(part.Parent).UserId
"list[#list+1]", #list means the amount of values inside of "list", and then the "+1" is necessary as it basically says "length of list plus 1, or insert a value to the end of the list". We then say that it is equal to the player userId. We do this by getting the player instance (For the userId) by the character instance. Which is where "GetPlayerByCharacter()" comes in handy, we give it the character instance (aka part.Parent) and it returns the player instance. Great! We have the player instance. Now we add ".UserId" to the end of that function and we have the userId stored. The rest is up to you!
Apologies for any mistakes. Let me know about them.
9 comments
I'm not sure you can get a group of players who are touching a part.
Maybe you could get each individual player and add them to a list?
What do you mean buy list?
by
Something like a table.
It's complicated. It really depends on what you want to do in particular. Could you maybe define why you want to do this?
So far, I have a lobby, and I want to teleport a specific group of players to a reserved server. I have the code for the teleport and the reserved server written out, but I need a part that players go into, get put into a table, and then get teleported with the rest of the people in that table.
^^ Just for clarification, this object they touch is like, in the doorway for a certain room or such?
Yeah. They go into a car, and then the car drives away into a tunnel, and the part would be inside of the tunnel.