The script SOMEHOW isn’t breaking or stopping. It just prints “ACTIVE” all the time and it always works even if the objects don’t exist.
Help!
for _, child2 in ipairs(child:GetChildren()) do
if string.match(child2.Name, "CannonProperty_") then
if not child:FindFirstChild("CannonApplied_" .. string.sub(child2.Name, 16, 99999)) then
local side = string.sub(child2.Name, 16, 99999)
local bool = Instance.new("BoolValue")
bool.Parent = child
bool.Name = "CannonApplied_" .. side
--print(side)
coroutine.wrap(function()
while task.wait() do
print("ACTIVE")
if not child then print("STOPPED") break end
if not child2 then print("STOPPED") break end
if child:FindFirstChild("CannonProperty_" .. side) then
if side == "Right" and child and child2 then
local leftDirection = Vector3.new(-1, 0, 0)
child.AssemblyLinearVelocity = leftDirection * -child2.Value
task.wait(0.1)
elseif side == "Left" and child and child2 then
local leftDirection = Vector3.new(1, 0, 0)
child.AssemblyLinearVelocity = leftDirection * child2.Value
task.wait(0.1)
elseif side == "Front" and child and child2 then
local leftDirection = Vector3.new(0, 0, 1)
child.AssemblyLinearVelocity = leftDirection * -child2.Value
task.wait(0.1)
elseif side == "Back" and child and child2 then
local leftDirection = Vector3.new(0, 0, -1)
child.AssemblyLinearVelocity = leftDirection * child2.Value
task.wait(0.1)
elseif side == "Top" and child and child2 then
local leftDirection = Vector3.new(0, 1, 0)
child.AssemblyLinearVelocity = leftDirection * child2.Value
task.wait(0.1)
elseif side == "Bottom" and child and child2 then
local leftDirection = Vector3.new(0, -1, 0)
child.AssemblyLinearVelocity = leftDirection * -child2.Value
task.wait(0.1)
else
print("AAAAAA")
end
else
break
end
end
end)()
end
end
end
When you are deleting things in the explorer, I believe that you are only doing it from the client’s side (hence the server doesn’t see these changes). If you change the run mode from Client to Server, then attempt to delete the things from explorer, does it work as expected?
game:GetService("RunService").Heartbeat:Connect(function()
if game.Workspace.Blocks:FindFirstChild("Blocks") then
local a = game.Workspace.Blocks:FindFirstChild("Blocks")
if #a:GetChildren() ~= 0 then
for _, child in pairs(a:GetChildren()) do
child.Parent = game.Workspace.Blocks
end
else
a:Destroy()
end
end
for _, child in pairs(game.Workspace.Blocks:GetChildren()) do
for _, child2 in ipairs(child:GetChildren()) do
if string.match(child2.Name, "CannonProperty_") then
if not child:FindFirstChild("CannonApplied_" .. string.sub(child2.Name, 16, 99999)) then
local side = string.sub(child2.Name, 16, 99999)
local bool = Instance.new("BoolValue")
bool.Parent = child
bool.Name = "CannonApplied_" .. side
--print(side)
print("ADDED")
coroutine.wrap(function()
repeat
print(child.Name)
print(child2.Name)
if not child then
print("STOPPED: Child is nil")
break
end
if not child2 then
print("STOPPED: Child2 is nil")
break
end
if child:FindFirstChild("CannonProperty_" .. side) then
if side == "Right" and child and child2 then
local leftDirection = Vector3.new(-1, 0, 0)
child.AssemblyLinearVelocity = leftDirection * -child2.Value
task.wait(0.1)
elseif side == "Left" and child and child2 then
local leftDirection = Vector3.new(1, 0, 0)
child.AssemblyLinearVelocity = leftDirection * child2.Value
task.wait(0.1)
elseif side == "Front" and child and child2 then
local leftDirection = Vector3.new(0, 0, 1)
child.AssemblyLinearVelocity = leftDirection * -child2.Value
task.wait(0.1)
elseif side == "Back" and child and child2 then
local leftDirection = Vector3.new(0, 0, -1)
child.AssemblyLinearVelocity = leftDirection * child2.Value
task.wait(0.1)
elseif side == "Top" and child and child2 then
local leftDirection = Vector3.new(0, 1, 0)
child.AssemblyLinearVelocity = leftDirection * child2.Value
task.wait(0.1)
elseif side == "Bottom" and child and child2 then
local leftDirection = Vector3.new(0, -1, 0)
child.AssemblyLinearVelocity = leftDirection * -child2.Value
task.wait(0.1)
else
print("Unrecognized side")
end
else
print("STOPPED: CannonProperty_" .. side .. " not found")
break
end
until not child or not child2
end)()
end
end
end
if child:FindFirstChild("IceProperty") and not child:FindFirstChild("IceApplied") then
local ice = Instance.new("BoolValue")
ice.Name = "IceApplied"
ice.Parent = child
if not child.CustomPhysicalProperties then
local defaultFriction = 0.3
local defaultElasticity = 0.5
local defaultDensity = 1
local defaultFrictionWeight = 1
local defaultElasticityWeight = 1
child.CustomPhysicalProperties = PhysicalProperties.new(
defaultDensity,
defaultFriction,
defaultElasticity,
defaultFrictionWeight,
defaultElasticityWeight
)
end
local currentProps = child.CustomPhysicalProperties
child.CustomPhysicalProperties = PhysicalProperties.new(
currentProps.Density,
0,
currentProps.Elasticity,
100,
currentProps.ElasticityWeight
)
elseif child:FindFirstChild("IceApplied") and not child:FindFirstChild("IceProperty") then
child:FindFirstChild("IceApplied"):Destroy()
child.CustomPhysicalProperties = nil
end
end
end)