-
What do you want to achieve?
A capture zone -
What is the issue?
When the palyer enters the zone, it starts a loop to change color etc… and prints (“Alpha”), every 2 seconds.
After 6 seconds the clients starts making errors, even if everything is working fine.
It will keep doing the errors until it has around the same amount as the printed Alphas -
What solutions have you tried so far?
Tried to put print statements all over in the local script, but nothing was printed when the errors occured.
and only alpha is printed around the time when the error occours
Local Script:
local currentTween = nil
Capturing.OnClientEvent:Connect(function(TF:boolean)
local Capture = wfc(HUDContainer, "Capturing")
local tweenInfo = TweenInfo.new(15, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
Capture.Visible = TF
if TF then
Capture.Bar.Size = UDim2.new(0, 0, Capture.Bar.Size.Y.Scale, Capture.Bar.Size.Y.Offset)
if currentTween then
currentTween:Cancel()
currentTween = nil
end
currentTween = TweenService:Create(Capture.Bar, tweenInfo, {Size = UDim2.new(1, 0, Capture.Bar.Size.Y.Scale, Capture.Bar.Size.Y.Offset)})
currentTween:Play()
currentTween.Completed:Connect(function()
Capture.Visible = false
if currentTween then
currentTween = nil
end
end)
local function updateText()
while Capture.Visible do
for i = 0, 3 do
Capture.TextLabel.Text = "Capturing" .. string.rep(".", i)
wait(0.5)
end
end
end
spawn(updateText)
else
if currentTween then
currentTween:Cancel()
currentTween = nil
end
Capture.Visible = false
end
end)
Server Script
local function startColorLoop(oldColor, teamColor, player)
local originalColor = oldColor
local loopStartTime = tick()
local Capturing = true
local iterationCounter = 0
while tick() - loopStartTime < 15 and Capturing do
local Array = zone:getPlayers()
if #Array <= 0 then
Capturing = false
CaptureRE:FireClient(player, false)
print("Player Left Zone")
break
end
for _, v in pairs(Array) do
if v.Team.TeamColor ~= teamColor then
Capturing = false
print("Enemy detected")
CaptureRE:FireClient(player, false)
break
end
end
if not Capturing then
break
end
tm.Value = teamColor
updatecolor()
wait(0.5)
tm.Value = originalColor
updatecolor()
wait(0.5)
iterationCounter = iterationCounter + 1
if iterationCounter == 2 then
print("alpha")
UpdateDataStore:Fire(player, flag, "Capturing")
iterationCounter = 0
end
end
if Capturing then
tm.Value = teamColor
updatecolor()
UpdateDataStore:Fire(player, flag, "Captured")
else
tm.Value = originalColor
updatecolor()
end
end
zone.playerEntered:Connect(function(player)
if tm.Value ~= player.TeamColor then
CaptureRE:FireClient(player, true)
coroutine.wrap(startColorLoop)(tm.Value, player.TeamColor, player)
end
end)
I have absolutely no idea what causes it