ok so i have made a tool that uses instance to spawn a part and despawns it with no problem but i want to make the part that spawns do something but first i need to find it in my workspace but i don’t know how to do that if it hasn’t spawned yet i tried WaitForChild but it gives out an infinite yield so i want to know how i can find and use the part to make it do stuff like give out a particle or change the value of cash of the player the only thing i want to know is how can i make the part into a variable and use it.
thanks for any help.
Edit: i found out how to do it myself hope it helps you too.
local part = Instance.new("Part")
part.Name == "SpecialPart"
wait(math.random(6,8)) — wait a random time
part.Parent = workspace — add part to workspace
In a different script detecting when the part was added.
workspace.DescendantAdded:Connect(function(descendant)
if descendant.Name == "SpecialPart" then — the name of the part I created in a different script
— run the code, the part was added
end
end)
game.Workspace.part
Okay to use but won’t work if your workspace is named something different. workspace.part
workspace will always be a valid instance.