kent911t
|
  |
| Joined: 06 Jul 2011 |
| Total Posts: 18 |
|
|
| 06 Apr 2017 06:32 PM |
My objective is to get everything in the workspace, compare it to every player's name and if it doesn't match any of them output the name of the object.
this code will work if there is only 1 player in the server:
for _, v in pairs(game.Players:GetChildren()) do for _, v2 in pairs (workspace:GetChildren()) do if v2:FindFirstChild("Humanoid") then if v2.Name ~= v.Name then print(v.Name) end end end end
however if there are 2 or more then it will take 1 name and try comparing it to 2 characters in the workspace, which will output 1 player's name
i don't want this happening
any help?
aaaaaaaaaaaaaaaaaaaaahhhh |
|
|
| Report Abuse |
|
|
end_itt
|
  |
| Joined: 27 Aug 2011 |
| Total Posts: 70 |
|
|
| 06 Apr 2017 06:36 PM |
| you could just target players in Players then do Player.Character might work idk #### |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2017 06:52 PM |
function compareObjectsinWorkspace() local players = game:GetService("Players"):GetPlayers() -- Get the players in-game local playerlist = table.concat(players, ", ") -- Create a list of everyone print("Players: "..playerlist) for _,obj in pairs(workspace:GetChildren()) do -- Find all objects in workspace if string.find(playerlist:lower(), obj.Name:lower()) then -- If the objects name is found in the player list, print the object name print("Object found: "..obj.Name) end end end
Came up with this on the spot, may need tweaking but otherwise, I think it suits your need.
What it does is create a single string containing the names of everyone in the server. If an object in the workspace does not have their name inside this string, print the objects name. You should note this checks for every player simultaneously, not one at a time.
|
|
|
| Report Abuse |
|
|
kent911t
|
  |
| Joined: 06 Jul 2011 |
| Total Posts: 18 |
|
|
| 06 Apr 2017 07:15 PM |
thanks, never knew about the table.concat function
aaaaaaaaaaaaaaaaaaaaahhhh |
|
|
| Report Abuse |
|
|