Why does the following work? I am trying to get my head around Object.IsValid.
Here is what is working...
function OnBeginOverlap(theTrigger, player)
-- The object's type must be checked because CoreObjects also overlap triggers, but we
if player and player:IsA("Player") then
if Object.IsValid(spawnedHealth) then
spawnedHealth:Destroy()
propPickupItem:Play()
script.parent:SetWorldPosition(triggerInitialLocation)
else
onRoundStart()
end
end
end
Whereas when I had the following code it would throw this error "Attempted to access an object that has been destroyed. Consider using Object.IsValid(myObject) to check for this condition."...
function OnBeginOverlap(theTrigger, player)
-- The object's type must be checked because CoreObjects also overlap triggers, but we
if player and player:IsA("Player") then
spawnedHealth:Destroy()
propPickupItem:Play()
script.parent:SetWorldPosition(triggerInitialLocation)
onRoundStart()
end
end
Can someone walk me through what is happening. Feels like a timing thing maybe. The destroy is happening so fast that it is running the onRoundStart code which contains the spawnedHealth variable which was destroyed already?