while true do
wait(.1)
if #game.Workspace.MapStorage:GetChildren() == 1 then
script.Parent.Region.Script.Disabled = true
elseif #game.Workspace.MapStorage:GetChildren() == 0 then
script.Parent.Region.Script.Disabled = false
end
end
I haven’t used studio in a long time, but as the title says, what is another way to “loop-check” this?
This gives my game lag because it checks every 0.1 second if something happens.
Instead of looping it every 0.1 seconds just to check for the changes you could use ChildAdded and ChildRemoved instead.
game.Workspace.MapStorage.ChildAdded:Connect(function()
if #game.Workspace.MapStorage:GetChildren() == 1 then
script.Parent.Region.Script.Disabled = true
elseif #game.Workspace.MapStorage:GetChildren() == 0 then
script.Parent.Region.Script.Disabled = false
end
end)
game.Workspace.MapStorage.ChildRemoved:Connect(function()
if #game.Workspace.MapStorage:GetChildren() == 1 then
script.Parent.Region.Script.Disabled = true
elseif #game.Workspace.MapStorage:GetChildren() == 0 then
script.Parent.Region.Script.Disabled = false
end
end)
local mapStorage = game.Workspace.MapStorage
local function checkChildren()
local numChildren = #mapStorage:GetChildren()
if (numChildren <= 1) then
script.Parent.Region.Script.Disabled = (numChildren == 1)
end
end
mapStorage.ChildAdded:Connect(checkChildren)
mapStorage.ChildRemoved:Connect(checkChildren)
checkChildren() -- May or may not be required