local function MakeOrb(Hole , Value)
if Value == nil then
spawn(function()
local orb = game.ReplicatedStorage.Orb:Clone()
orb.Parent = workspace
Hole.Sphere.Value = orb
orb.Position = Hole.Position - Vector3.new(0,3,0)
orb.BodyVelocity.Velocity = Vector3.new(0,5,0)
repeat
wait()
until orb.Position.Y > Hole.Position.Y + 2.5
orb.BodyVelocity.Velocity = Vector3.new(0,0,0)
end)
end
end
for i , v in pairs(script.Parent.Holes:GetChildren()) do
MakeOrb(v , nil)
v.Sphere:GetPropertyChangedSignal("Value"):Connect(function(Value)
print(v.Sphere.Value)
MakeOrb(v , v.Sphere.Value)
end)
end
This script copies an orb instance to the workspace and does it again when the orb is deleted, problem is, i was relying on the orb being destroyed counting as a change in objectValue’s value, this doesn’t seem to be the case.
What can I do then?
Listen for the sphere itself to change instead, destroying an instance parents it to nil (among other things) which fires the .AncestryChanged event before all of the connections are disconnected. Also, try returning the orb just to make things easier:
local function handleAncestryChanged(orb)
v.Sphere.Value = orb
orb.AncestryChanged:Connect(function()
if not orb.Parent then
print('Orb was destroyed or parented to nil!')
handleAncestryChanged(makeOrb(v))
end
end)
end
handleAncestryChanged(makeOrb(v))