I'm trying to give multiple parts a visible region3 where when you enter it a gui is enabled. The gui's timer goes up to sixty 60 seconds, gives money, then resets back to zero. It repeats this process as long as you're still in the region. When you leave it, the gui is disabled.
When assigning just ONE specific part a region3,the script works just fine. However, once I added the for loop in order to assign more than one part a region3, none of the parts work. The gui does not show up at all for any of them.
Is starterGui not compatible with more than one region3? Or is the way I'm giving the parts a region3 with the issue?
screenshot of the folder: https://imgur.com/a/Br8MyBN
local gui = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
for _, part in pairs(game.Workspace.Jobs.OfficeJob:GetChildren()) do
local Region = Region3.new(part.Position - (part.Size/2),part.Position + (part.Size/2))
while wait() do --keeps going as soon as you run the game
--second parameter means workspace will keep detecting if any of the local player's character parts are in region, no need to check again cause it's a whitelist
local Detect = workspace:FindPartsInRegion3WithWhiteList(Region,Character:GetDescendants(),math.huge)
local timer = gui.Frame.Timer
local seconds = timer.seconds
local cash = Player.Stats.pocketMoney
local TotalAmountLabel = gui.Frame.TotalAmount
local amount = TotalAmountLabel.amount
if #Detect > 0 then
gui.Enabled = true
timer.Text = seconds.Value
TotalAmountLabel.Text = "$" .. amount.Value
wait(1)
seconds.Value = seconds.Value - 1
if seconds.Value == 0 then
cash.Value = cash.Value + 500
amount.Value = amount.Value + 500
seconds.Value = 5
end
else if #Detect == 0 then
gui.Enabled = false
seconds.Value = 5
amount.Value = 0
timer.Text = seconds.Value
TotalAmountLabel.Text = amount.Value
end
end
end
end

1 comment
It still doesn't work. I used print() statements to test if it even reaches if conditions.