Trying to find a specific object inside of a table

I’m trying to find a specific object that’s inside of a table. I know that it’s in the table because when I print it out, I can see it within the table, for some reason the script can’t see that it’s in the table though, and it’s only returning nil.

How do I fix this? . . Is there something that I’m missing? I’ve used table.find before without any errors, and I’ve been scouring the devforum for an answer for a while

2 Likes

Is the NearbyObjects table also a dictionary?

3 Likes

You were on the right track with table.find, but you tried searching for a string instead of an object, which the table that :GetPartBoundsInRadius() returns never contains a string.

3 Likes

Honestly, I have no idea, I just started using collection service

1 Like

It’s still not working or printing anything, unless I’m doing something wrong? Also, I’m certain the object is in the table, I can print NearbyObjects alone and screenshot the table and it’ll be there

1 Like

I’m pretty sure the way you were debugging was by using tostring(NearbyObjects) but that returns strings you cannot use string when trying to find instances. a way you could do this is

local PlayerFound = false
for _, i in NearbyObjects do
if i.Name == "Head" then
PlayerFound = true
end
end

and then use PlayerFound instead of table.find
(edit: i cant put indents for some reason)

3 Likes

HumanoidRootPart is not a defined variable. You have to define it.

3 Likes

How would I define it? What I’m trying to do is check for any humanoids near a sliding door, and have the script print something the moment that it triggers, if I defined the HumanoidRootPart beforehand then it would only work for a single player

I want it to trigger when any player is near the door, not a specific one

2 Likes

I’ll try this, so there’s no way to do it with table.find? . . I remember being able to do it so easily before, that’s why I’m surprised

1 Like

table.find() wouldn’t work with instances since every instance is unique

2 Likes

You could loop through every player and check if the table has the player’s humanoidrootpart

for _,plr in pairs(game.Players:GetPlayers()) do
   if plr.Character and table.find(NearbyObjects,plr.Character.HumanoidRootPart) then
      -- do stuff
   end   
end
2 Likes

I’ll implement this when I’m back from my break, thank you both for the solution

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.