Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Value decreasing by two after a time?

Asked by
rexhawk 222 Moderation Voter
5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago
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

Ad

Answer this question