I want to make a Control The Points minigame, and I’m running this coroutine that runs an animation for when a team is claiming the point, if a different team comes in the point, I can yield it and stuff.
The thing is in the coroutine, I need to run a task.wait() in the for loop so it takes the right amount of time to capture the point. And due to a function checking which team is the most in the circle for every circle this error is popping up and I can’t think of a loop around it.
Can someone help?
local claimingf = coroutine.create(function(team)
local capturebar = v.ball.gui.CaptureProgressBar
if claiming == false then
claiming = true
currentlyClaiming = team
capturebar.Bar.BackgroundColor3 = game.ReplicatedStorage.CONFIGURATION.COLORS[team].Value
capturebar.Bar.Size = UDim2.new(0, 0, 1.055, 0)
for i = 0, 1, 0.01 do
task.wait(timetoclaim/100)
capturebar.Bar.Size = UDim2.new(i, 0, 1.055, 0)
end
v.claimed.Value = team
v.circle.Color = game.ReplicatedStorage.CONFIGURATION.COLORS[team].Value
for _, b in pairs(v.ball:GetChildren()) do
b.Color = game.ReplicatedStorage.CONFIGURATION.COLORS[team].Value
end
claiming = false
end
end)
local function checkAndClaim()
local hteam, highest = 0, ""
for _, t in pairs(game.ReplicatedStorage.Teams:GetChildren()) do
local amountfromteam = 0
for _, e in pairs(v.playersInArea:GetChildren()) do
if e.Value == t.Name then
amountfromteam += 1
end
end
if amountfromteam > hteam then
if highest ~= t.Name then
hteam = amountfromteam
highest = t.Name
end
end
end
if highest ~= "" then
if highest ~= v.claimed.Value then
if coroutine.status(claimingf) ~= "running" then
coroutine.resume(claimingf, highest)
end
end
end
task.wait()
checkAndClaim()
end