Broken Loop In script

Ive been having a problem tryng to loop a code and stop it when a quota is met. For example, turn the baseplate green when there is under 2 players in the game, if larger than 2, turn the baseplate grey.How can i do the same for this?
Code -
AppleDropScript

local tree = script.Parent
local configs = require(script.DropConfigurations)
local apples = tree.Apples:GetChildren()
local apple = script.Apple
apple.Parent = game.ServerStorage

while true do
	local waitTime = math.random(configs.MinWaitForApple, configs.MaxWaitForApple)
	local numApples = #tree.DroppedApples:GetChildren()
-- TODO thing i wanna fix VVV
	while numApples >= 4 do
		script.Parent.TrunkandBranches.Base.g.t.Text = "You can not have more than 4 apples dropped, pick up a apple to continue!"
		wait()
	end
	script.Parent.TrunkandBranches.Base.g.t.Text = "10"	
for i = 1, 10, 1 do
		script.Parent.TrunkandBranches.Base.g.t.Text = script.Parent.TrunkandBranches.Base.g.t.Text - 1
		wait(1)
end
	local applePos = apples[math.random(#apples)]
	local newApple = apple:Clone()
	newApple.Parent = script.Parent.DroppedApples
	newApple.Handle.CFrame = applePos.CFrame
	newApple.Handle.Anchored = false
	newApple.Handle.RotVelocity = Vector3.new(math.random(-1,1), math.random(-1,1), math.random(-1,1))
end

DropConfigurations (ModuleScript)

local Configurations = {}

Configurations.MaxApplesAtATime = 5 -- the maximum amount of apples that can be on the ground at one time
Configurations.MaxWaitForApple = 1	-- the maximum amount of time that can pass before an apple will fall from the tree
Configurations.MinWaitForApple = 1	-- the minimum amount of time that can pass before an apple will fall from the tree

return Configurations

The loop in AppleDropScript is broken, and i want it fixed. Can anyone fix it and demonstrate how to do it properly?
Thanks

Yes, I’m also using the Apple Orchard model, I just want to edit it.

Your loop is not ending because its condition will always be met, that is, you’re not updating the value within the loop. Have you tried updating the value within the loop?

local numApples = #tree.DroppedApples:GetChildren()

while numApples >= 4 do
		script.Parent.TrunkandBranches.Base.g.t.Text = "You can not have more than 4 apples dropped, pick up a apple to continue!"
		wait()
		local numApples = #tree.DroppedApples:GetChildren() -- it needs to update
end

This code is also somewhat inefficient, but I guess at the very least it works.

It seems that its not working. Thanks for helping though.

The problem in their script is the local for the second numApples

	local numApples = #tree.DroppedApples:GetChildren()

	while numApples >= 4 do
		script.Parent.TrunkandBranches.Base.g.t.Text = "You can not have more than 4 apples dropped, pick up a apple to continue!"
		wait()
		numApples = #tree.DroppedApples:GetChildren() -- it needs to update
	end
2 Likes