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
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.
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
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)
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
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