I am trying to detect when a tree or a rock in the workspace disappears, but I can't figure it out. My only guess is to detect if a a tree/rock was destroyed and then fire it to all clients. However, what if I lose two at a time? Then it won't fire. Can someone help me? This is my attempt.
local rEvent = workspace.ResourceEvent
while wait(1) do
oldnumber = 0
for _,v in pairs(workspace:GetChildren()) do
if v:IsA("Model") and v.Name == "Tree" or v:IsA("Model") and v.Name == "Rock" then
oldnumber = oldnumber + 1
end
end
newnumber = 0
for _,v in pairs(workspace:GetChildren()) do
if v:IsA("Model") and v.Name == "Tree" or v:IsA("Model") and v.Name == "Rock" then
newnumber = newnumber + 1
end
end
if newnumber > oldnumber then
workspace.ResourecEvent:FireServer() -- Another problem, how do I detect if I lost a rock/tree? It could be both.
end
end

3 comments
Change it to wait(0). I'm sure that will fix your problem.
it only made it run quicker
Could you then please explain your problem better? From what you've said, I only understand that you want it to Fire everytime a Rock/Tree dissapears.