local redcapturemultiplier = 0
local bluecapturemultiplier = 0
script.Parent.Touched:connect(function(hit)
local player = game.Players:FindFirstChild(hit.Parent.Name)
local debounce = false
if player ~= nil and debounce == false then
if hit.Name == "Torso" then
debounce = true
if hit.Parent:FindFirstChild("capture") == nil and hit.Parent.Humanoid.Health > 0 then
local CaptureValue = Instance.new("StringValue")
CaptureValue.Name = "capture"
CaptureValue.Parent = hit.Parent
print("made value")
if tostring(player.TeamColor) == "Bright red" then
script.Parent.Parent.RedsOnPoint.Value = script.Parent.Parent.RedsOnPoint.Value + 1
else
script.Parent.Parent.BluesOnPoint.Value = script.Parent.Parent.BluesOnPoint.Value + 1
end
end
debounce = false
end
end
end)
script.Parent.TouchEnded:connect(function(hit)
local player = game.Players:FindFirstChild(hit.Parent.Name)
local debounce = false
if player ~= nil and debounce == false then
if hit.Name == "Torso" then
debounce = true
if hit.Parent:FindFirstChild("capture") ~= nil then
hit.Parent.capture:Destroy()
if tostring(player.TeamColor) == "Bright red" then
script.Parent.Parent.RedsOnPoint.Value = script.Parent.Parent.RedsOnPoint.Value - 1
else
script.Parent.Parent.BluesOnPoint.Value = script.Parent.Parent.BluesOnPoint.Value - 1
end
print("destroy value")
end
end
end
end)
script.Parent.Parent.BluesOnPoint.Changed:connect(function(NewValue)
bluecapturemultiplier = NewValue
end)
script.Parent.Parent.RedsOnPoint.Changed:connect(function(NewValue)
redcapturemultiplier = NewValue
end)
local stop = false
while wait(0.9) do
if script.Parent.Parent.BluesOnPoint.Value > 0 and script.Parent.Parent.RedsOnPoint.Value > 0 then
stop = true
end
if stop == false then
if script.Parent.Parent.BluesOnPoint.Value > 0 then
if script.Parent.Parent.CaptureProgress.Value ~= -100 then
wait(0.1)
script.Parent.Parent.CaptureProgress.Value = script.Parent.Parent.CaptureProgress.Value + (-1 * bluecapturemultiplier)
if script.Parent.Parent.CaptureProgress.Value == -100 then
script.Parent.Parent.Owner.Value = "Blue"
script.Parent.BrickColor = BrickColor.new(315)
script.Parent.Parent.Union.BrickColor = BrickColor.new(23)
script.Parent.Parent.Particles.ParticleEmitter.Color = ColorSequence.new(Color3.fromRGB(0,170,255))
print("Blue has captured the point!")
end
if script.Parent.Parent.CaptureProgress.Value == 0 then
script.Parent.Parent.Owner.Value = "Nobody"
script.Parent.BrickColor = BrickColor.new(1001)
script.Parent.Parent.Union.BrickColor = BrickColor.new(199)
script.Parent.Parent.Particles.ParticleEmitter.Color = ColorSequence.new(Color3.fromRGB(255,255,255))
print("Point has been uncaptured!")
end
end
end
if script.Parent.Parent.RedsOnPoint.Value > 0 then
if script.Parent.Parent.CaptureProgress.Value ~= 100 then
wait(0.1)
script.Parent.Parent.CaptureProgress.Value = script.Parent.Parent.CaptureProgress.Value + (1 * redcapturemultiplier)
if script.Parent.Parent.CaptureProgress.Value == 100 then
script.Parent.Parent.Owner.Value = "Red"
script.Parent.BrickColor = BrickColor.new(21)
script.Parent.Parent.Union.BrickColor = BrickColor.new(21)
script.Parent.Parent.Particles.ParticleEmitter.Color = ColorSequence.new(Color3.fromRGB(255,0,0))
print("Red has captured the point!")
end
if script.Parent.Parent.CaptureProgress.Value == 0 then
script.Parent.Parent.Owner.Value = "Nobody"
script.Parent.BrickColor = BrickColor.new(1001)
script.Parent.Parent.Union.BrickColor = BrickColor.new(199)
script.Parent.Parent.Particles.ParticleEmitter.Color = ColorSequence.new(Color3.fromRGB(255,255,255))
print("Point has been uncaptured!")
end
end
end
end
stop = false
end
This is a script for an FPS I am working on - basically, its a control point that you can capture. For some reason, this server script lags the whole game whenever someone enters the the point. Is there any reason why? I can see it being linked to the while loop, but I don't know whats wrong with it.

1 comment
Why do you have the denounce reset immediately after touch? If its the touch event that causes the lag, that would be the problem