Is there a way to detect an instance without requiring the name?

I am trying to make a script that detects a folder, then gets the child of that folder, however it is not working right.
I need it to dectect the instance because the folders name is always going to be the players user ID.

local data = game.ReplicatedStorage.PlayerData:FindFirstAncestorWhichIsA("Folder")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if data:FindFirstChild("Stats").Time.Value == 1 then
			game.ServerScriptService.DataStorer_DataStore.Plr.Secret=true
			print("True")
		end
	end
end)

I get this error in return:

I am trying to reach the stats folder:
image

Any ideas on how to detect this folder and the children?

You can add a…

repeat task.wait() until game.ReplicatedStorage.PlayerData:FindFirstAncestorWhichIsA("Folder")

in the first line to make sure the folder is not empty when you are retrieving the data.

I believe that you meant to use FindFirstDescendantWhichIsA instead?

local data = game.ReplicatedStorage.PlayerData:FindFirstDescendantWhichIsA("Folder")
1 Like

Thank you. This removed the error.

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