spawn(function()
while wait(0.1) do
for _, obj in pairs(character:GetDescendants()) do
if obj.Name == "Stick" then
print("Found Stick inside".. obj.Parent.Name)-- that sounds so wrong lol
end
end
end
end)
spawn(function()
while wait(0.1) do
for i,v in pairs (workspace:GetDescendants()) do
if v.Name == "Stick" then
print("the workspace check has found a Stick inside"..v.Parent.Name)
end
end
end)
If you expect the stick to be in the workspace with it being itâs parent and you expect the stick to be in a characterâs humanoid rootpart, you donât need to use GetDescendants() on the workspace at all.
Yes, Players:GetPlayers() returns a list/table of players in the game, if you just need to check if the humanoidrootpart has a stick, you just go through that list and use FindFirstChild to see if thereâs a rootpart and also check if thereâs a stick and if thereâs a stick you can use FindFirstChild on the workspace to get rid of the stick.
What FindFirstChild does is check if there is something called what youâre calling for right under the parent.
@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
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()
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
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