In my round restart script, I noticed that the following code would run forever:
for i,v in pairs(game.Players:GetPlayers()) do
print('ok1')
v.Character.Humanoid.MaxHealth = math.huge
v.Character.Humanoid.Health = math.huge
end
and:
for i,v in pairs(game.Players:GetPlayers()) do
print('ok2')
v.Character.Humanoid.Health = 0
end
Is this a feature to the for loops, or am I doing something wrong? If this is the case, then how would I use this method to configure every player only once?
Full server script:
local folder = script.Parent
local restartvalue = folder:WaitForChild("Restart")
local rs = game:GetService("ReplicatedStorage")
local restartstuff = folder:WaitForChild("RestartStuff")
local timer = restartstuff:WaitForChild("Script")
local pointfolder = workspace:WaitForChild("CapturePoints")
local pa = workspace:WaitForChild("CapturePointA")
local pb = workspace:WaitForChild("CapturePointB")
local pc = workspace:WaitForChild("CapturePointC")
local hill = workspace:WaitForChild("CapturePointCentral")
restartvalue.Changed:Connect(function()
if restartvalue.Value == true then
restartvalue.Value = false
for i,v in pairs(game.Players:GetPlayers()) do
print('ok1')
v.Character.Humanoid.MaxHealth = math.huge
v.Character.Humanoid.Health = math.huge
end
wait(10)
for i,v in pairs(pointfolder:GetChildren()) do
v.Value = "NEUTRAL"
end
for i,v in pairs(pa.CircleThings:GetChildren()) do
v.BrickColor = BrickColor.new("Medium stone grey")
end
for i,v in pairs(pb.CircleThings:GetChildren()) do
v.BrickColor = BrickColor.new("Medium stone grey")
end
for i,v in pairs(pc.CircleThings:GetChildren()) do
v.BrickColor = BrickColor.new("Medium stone grey")
end
for i,v in pairs(hill.CircleThings:GetChildren()) do
v.BrickColor = BrickColor.new("Medium stone grey")
end
folder.Countdown.Minutes.Value = "15"
folder.Countdown.Seconds.Value = "0"
pa.CircleThings.CapturePoint.Point.TextLabel.TextColor3 = Color3.new(255,255,255)
pa.CircleThings.BigCircle.SurfaceLight.Brightness = 0
pa.CircleThings.BigCircle.SurfaceLight.Color = Color3.new(255,255,255)
pb.CircleThings.CapturePoint.Point.TextLabel.TextColor3 = Color3.new(255,255,255)
pb.CircleThings.BigCircle.SurfaceLight.Brightness = 0
pb.CircleThings.BigCircle.SurfaceLight.Color = Color3.new(255,255,255)
pc.CircleThings.CapturePoint.Point.TextLabel.TextColor3 = Color3.new(255,255,255)
pc.CircleThings.BigCircle.SurfaceLight.Brightness = 0
pc.CircleThings.BigCircle.SurfaceLight.Color = Color3.new(255,255,255)
hill.CircleThings.CapturePoint.Point.TextLabel.TextColor3 = Color3.new(255,255,255)
hill.CircleThings.BigCircle.SurfaceLight.Brightness = 0
hill.CircleThings.BigCircle.SurfaceLight.Color = Color3.new(255,255,255)
local timerclone = timer:Clone()
for i,v in pairs(game.Players:GetPlayers()) do
print('ok2')
v.Character.Humanoid.Health = 0
end
wait(5)
folder.Countdown.Script:Destroy()
timerclone.Parent = folder.Countdown
timerclone.Disabled = false
end
end)
