Hello, I'm making a terminal and it has a while loop that adds +1 to a intValue. Whenever it runs it just spams +1.
I have filtering enabled, I am using a server script.
--tIme is defined up more in the script while tIme.Value < 10 do --runs when tIme.Value is lower than ten, low number for testing wait(1) --Wait nevers waits tIme.Value = tIme.Value + 1 -- adds 1 to the value end
Any help would be appreciated.
EDIT: Whole script.
local gameRunning = game:GetService("ServerScriptService").Start.running local beam = script.Parent.Parent.Beam local text = game:GetService("ServerScriptService").Start.text local timer = game:GetService("ServerScriptService").Start.timer local tIme = script.Parent.time script.Parent.Touched:connect(function(hit) if gameRunning.Value == false then return end if hit.Parent:FindFirstChild("Humanoid") then local char = hit.Parent local plr = game.Players:GetPlayerFromCharacter(char) if plr.TeamColor == BrickColor.new("Really red") then beam.BrickColor = BrickColor.new("Really red") text.Value = "Red team owns the hill!" --Here to while tIme.Value < 10 do wait(1) tIme.Value = tIme.Value + 1 end --Here text.Value = "Red has won!" elseif plr.TeamColor == BrickColor.new("Really blue") then beam.BrickColor = BrickColor.new("Really blue") text.Value = "Blue team owns the hill!" --Here while tIme.Value < 10 do wait(1) tIme.Value = tIme.Value + 1 end --Here text.Value = "Blue has won!" end end end)
Between the --here are where the while loops I am having problems with are.
You should try adding a debounce like this
local gameRunning = game:GetService("ServerScriptService").Start.running local beam = script.Parent.Parent.Beam local text = game:GetService("ServerScriptService").Start.text local timer = game:GetService("ServerScriptService").Start.timer local tIme = script.Parent.time local debounce = false script.Parent.Touched:connect(function(hit) if debounce == false then -- check debounce value debounce = true -- change debounce so it wont run again if gameRunning.Value == false then return end if hit.Parent:FindFirstChild("Humanoid") then local char = hit.Parent local plr = game.Players:GetPlayerFromCharacter(char) if plr.TeamColor == BrickColor.new("Really red") then beam.BrickColor = BrickColor.new("Really red") text.Value = "Red team owns the hill!" --Here to while tIme.Value < 10 do wait(1) tIme.Value = tIme.Value + 1 end --Here text.Value = "Red has won!" elseif plr.TeamColor == BrickColor.new("Really blue") then beam.BrickColor = BrickColor.new("Really blue") text.Value = "Blue team owns the hill!" --Here while tIme.Value < 10 do wait(1) tIme.Value = tIme.Value + 1 end --Here text.Value = "Blue has won!" end end debounce = false -- set it back once everything is done end end)