I dont know why but the wait function doesnt seem to be working
while allPlayersAlive() do wait(2.5) giveMoneyToPlayers() -- all players in a region give 5$ if allFinish() then -- returns true if all players are in brick region teleportToStart() break end end
so basically the loops is suppose to wait 2.5 seconds then
get all players in a room (players found using region 3) and give them 5$
then checks the finish region, and if all players are there, teleport them to the start and break the while loop
what is happening is it waits 2.5 seconds and then adds 80$ to the players balance, instead of 5$
im not sure why this is happening please help.
Change line 11 to "if r == player then" and see how that works.
local function giveMoney() local partsInRegion = workspace:FindPartsInRegion3(vaultRegion,nil,math.huge) local giveTo = {} for _,part in pairs(partsInRegion) do local player = game.Players:GetPlayerFromCharacter(part.Parent) if player then local playerFound = false for _,r in pairs(giveTo) do if r == player.Name then playerFound = true end end if not playerFound then table.insert(giveTo,player) end end end for _,player in pairs(giveTo) do local newAmount = player.leaderstats.CurBagAmount.Value + 5 if newAmount > player.leaderstats.BagSize.Value then newAmount = player.leaderstats.BagSize.Value end player.leaderstats.CurBagAmount.Value = newAmount end end