Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Value decreasing by two after a time?

I'm making a "prison" script in which when the suspect is sent here, it displays a "Time until release" gui that shows the time left in seconds. The problem is that either gradually or immediately, it starts to decrease by two, instead of one. This script is nested inside of a "Character Added" events inside of a "Player added" event. This is the only code that interacts with the time-left value, so this HAS to be the problem somehow, but I don't know how.

if p.TeamColor == BrickColor.new("Neon orange") then -- if player is on the "prison team"
	p:WaitForChild("PlayerGui"):WaitForChild("GameScreens"):WaitFor	Child("CornerGUI").Enabled = false
	enableJailGUIEvent:FireClient(p) -- enabled countdown GUI
	repeat
		jailTime:Increment(-1,0) -- Decreases the timeleft Value
		wait(1)
	until
		p:WaitForChild("Settings"):WaitForChild("Jail"):WaitForChild("JailTime").Value <= -1 -- until the time is below zero
	p.TeamColor = BrickColor.new("Bright blue") -- switch to citizen team
	p:LoadCharacter()
end

1 answer

if p.TeamColor == BrickColor.new("Neon orange") then -- if player is on the "prison team"
	p:WaitForChild("PlayerGui"):WaitForChild("GameScreens"):WaitFor	Child("CornerGUI").Enabled = false
	enableJailGUIEvent:FireClient(p) -- enabled countdown GUI
	debounce = false
	repeat
	if not debounce then
	debounce = true
		jailTime:Increment(-1,0) -- Decreases the timeleft Value
		wait(1)
		end
	until
		p:WaitForChild("Settings"):WaitForChild("Jail"):WaitForChild("JailTime").Value <= -1 -- until the time is below zero
	p.TeamColor = BrickColor.new("Bright blue") -- switch to citizen team
	p:LoadCharacter()
end

the debounce makes it only run once every second the rest of the script is urs

This discussion is preserved as it was. New answers, comments, and votes are closed.