Hello, I am trying to break the loop when proj stops existing, when the part is destroyed. I thought checking if it isn't nil would work but it's never nil and I can't check the parent folder for the child since it can contain multiple of them at once. I could set it to nil in the part of the script that will destroy it (for context it's a projectile that can get shot down by anti air) but coming up with a solution without that would be preferable for manual testing.
Thank you for any answers.
local W, RS, SS = game.Workspace, game:GetService("ReplicatedStorage"), game:GetService("ServerStorage")
local r = RS:WaitForChild("Launch")
local l = W.Launcher
local pF = W.Projectiles
local function Launch(plr, pos)
local proj = SS.Torpedo:Clone()
proj.Parent = pF
local p1 = proj.Position
local p3 = pos
local p2 = p1:lerp(p3, 0.5) + Vector3.new(0,50,0)
l.CFrame = CFrame.new(l.Position, Vector3.new(pos.X,l.Position.Y,pos.Z))
l.Shoot:Play()
p.Sound:Play()
for t = 0,1,0.01 do
if proj ~= nil then
local TP = QuadraticBezier(t , p1, p2, p3)
local TO = QuadraticBezier(t + 0.005 , p1, p2, p3)
proj.CFrame = CFrame.new(TP, TO)
wait()
end
end
end
r.OnServerEvent:Connect(Launch)

6 comments
Sadly doesn't work, the loop carries out until it's finished. I feel like it has something to do with how proj is defined, it always exists even if you destroy the instance, but it seems like the variable stays no matter the instance.
alright, if it doesn't work, try checking if proj exists using pF:WaitForChild(proj,1)? also, if it still doesn't work, try changing "proj" to the name of the object in the DataModel.
I tried both and more and no success either. The problem is that you can't look for the child using a instance, and if I search with the string of projs name, it could just return other projs in the same folder as there can be more at once.
well, sorry then, i cant help you then :( i hope someone that can finds this topic
I just realised my mistake, I've been deleting the proj on the client side during testing the whole time, therefore it's never been deleted. I was just about to implement numbering and realised that as FindFirstChild was finding it even thought i deleted it. I'm used to old studio when everything was serverside lmao, I got baited again.
hah, happens all of the time :)