What do you want to achieve?
I have a boss npc, and it creates a folder object named “battleStarted” and parents it to the npc when a player is within range and destroys it after killing the player/no more players in range
What is the issue?
The battleStarted folder just exists as a tag, and i want to have a function executed from another script only while the battleStarted object exists, however when i have tried solutions it either runs the loop when the object doesn’t exist, or doesn’t run it when the object does exist.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve seen a few topics but none of them really worked for what i was doing, so i’m making this post.
Tried this as nothing_1649’s solution wasn’t working, and i have it to print “detected”, but when i test the game, it repeatedly spam prints “detected” without the object being created, and when it is created, it stops, and then continues again when the object is removed
-- loop script code
char.ChildAdded:Connect(function(child)
if child.Name == "battleStarted" then
print('detected')
end
end)
Even though you said you found a solution, one issue with this code is using WaitForChild. WaitForChild will yield the current thread until a maximum time is reached. You should used FindFirstChild instead.