How to make a countdown decrease faster depending on a door's state

I made a door script and a text label script with a cooldown. I wan’t both of the scripts to be seperate and that’s how I have them. What I wan’t is the cooldown to decrease faster when the door is closed, but the issue is that I don’t know how to. My first idea was to somehow check in the text label script a debounce value that I have inside the door script, but searching on devforum didn’t help me. My second idea was to use the door’s position but that’s unreliable and didn’t work either. How will I be able to do something like that?

Textlabel script

local text = script.Parent
local countdown = 100

for count = -1, 100, 10 do
	countdown -= 1
	text.Text = countdown
	wait(1)
end
2 Likes

I think what you should do is to either place a BoolValue or a boolean attribute in the door that changes depending on the door’s state (true if the door is closed, false if the door is open)

Then in your countdown script, check the state of that boolean, if it’s true, make it wait a shorter time, if it’s false, use 1 second as you currently do

Example

if door:GetAttribute("IsClosed") then
    task.wait(0.5) -- Something less than than the open time
else
    task.wait(1)
end
4 Likes
local cooldown = door:GetAttribute("IsClosed") and 0.5 or 1

task.wait(cooldown)
2 Likes

How can I exactly insert a bool value inside a script?

You add it into the door itself, not the script.

No scripting required either, go into the explorer and from there add a BoolValue (or go into the properties of the door and create a new attribute if that’s what you prefer)

Then in your door code, when the door opens or closes, change the state of the boolean

1 Like

So I have to make a variable that refrences the boolean right?

Yes, in both your door code and your countdown code t here should be a variable that references the boolean itself so you can use it to change its state or check its state

1 Like

I got it working now, thanks a lot :+1:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.