Checking All Characters For Objects

I just want to check ALL of the players humanoid root parts for the child stick. If you could give me the script it would be much appreciated.

Cause i really dont get it. I tried the i,v loop n stuff i jsut dont get it.

What’s your new code @BMWLux ?

@DybalaplaysYT GetDescendants would get everything in the workspace that’s inside it, I think that’s unnecessary if the OP knows that a stick is going to be in the workspace and he only wants to check what’s inside a character’s humanoidrootpart

1 Like

but if you look at the original post, he said he wants to check if the object exists in the workspace and in any of the games humanoidrootparts

So basically Im trying to see if an object exists in the workspace and in any of the games 
humanidrootparts.

and GetDescendants() can do all of this in one thread

1 Like

this is the simplest i can do

for i,v in pairs (workspace:GetDescendants()) do

 if v.Name == "Stick" then
  print("Stick found")
 end

end

since the player’s Character HumanoidRootPart are descendants of workspace, It will check their HumanoidRootParts too

1 Like

it will? But like it will also find the workspace. How can I check if there is two of them and if so then delete one.

for i, plr in pairs(game.Players:GetChildren()) do
wait(0.1)
local character = plr.Character
for _, obj in pairs(character:GetChildren()) do
wait(0.1)
if obj.Name == “HumanoidRootPart” then
if character.HumanoidRootPart:FindFirstChild(“Stick”) then
game.Workspace:FindFirstChild(“Stick”):Destroy()

		print("ObjWithHRPFound")
		
		end
	end
end

end

But like is this possbile? If so how could I do it?

I think this script would help, did a boolean check if a rootpart has a stick and then it will check to destroy a stick in a workspace.

local Players = game:GetService("Players")
while true do
	local FoundStickInCharacter = false
	for _, Player in pairs (game.Players:GetChildren()) do
		if Player and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
			local RootPart = Player.Character:FindFirstChild("HumanoidRootPart")
			if RootPart:FindFirstChild("Stick") then
				FoundStickInCharacter = true
			end
		end
	end
	if FoundStickInCharacter == true and game.Workspace:FindFirstChild("Stick") then
		print("Stick found in child of workspace")
		game.Workspace:FindFirstChild("Stick"):Destroy()
	elseif FoundStickInCharacter == true and not game.Workspace:FindFirstChild("Stick") then
		print("No stick found in child of workspace")
	end
	wait(0.25)
end
2 Likes

Fr. If this works I will heart every one of your comments XD

local foundalreaady = false

for i,v in pairs (workspace:GetDescendants()) do

 if v.Name == "Stick" and foundalready == false and v.Parent ~= workspace then
  print("Stick found")
  v:Destroy()
  foundalready = true

  elseif v.Name == "Stick" and foundalready == true and v.Parent == workspace then
   print("Found a stick that is child of workspace. Keeping Stick.")
  end

end
1 Like

Same to you lol :smiley: Muchas Gracias

WORKS! :smiley: LETS GOOGOOO THANK YOU!