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