I am currently trying to create a button that when clicked will disable a wall for a set amount of time before the wall reappears. Currently due to the loop, the timer will display into the negatives and will never finish. But, if I don’t have the loop, then the timer will never go down. I want to do this without creating a long line of wait(1) then timerText = timerText - 1 and then Ttext.Text = timerText. Here is my current code for the button:
local timer = 10 --Input Time Given Here
local timerText = timer
local Ttext = script.Parent.BillboardGui.TGui
local deb = false
local button = script.Parent
local door = script.Parent.Parent.Door
local text1 = door.Texture1
local text2 = door.Texture2
local TweenService = game:GetService("TweenService")
local finishButton = {}
finishButton.Position = button.Position + Vector3.new(0,-0.5,0)
finishButton.Color = Color3.fromRGB(27, 42, 53)
local infoButton = TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local buttonTween = TweenService:Create(button, infoButton, finishButton)
local infoDoor = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
local doorTween = TweenService:Create(door, infoDoor, {Transparency = 1})
local T1Tween = TweenService:Create(text1, infoDoor, {Transparency = 1})
local T2Tween = TweenService:Create(text2, infoDoor, {Transparency = 1})
local finishButtonR = {}
finishButtonR.Position = button.Position + Vector3.new(0,0.5,0)
finishButtonR.Color = Color3.fromRGB(170, 85, 0)
local infoButtonR = TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local buttonTweenR = TweenService:Create(button, infoButtonR, finishButtonR)
local infoDoorR = TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
local doorTweenR = TweenService:Create(door, infoDoorR, {Transparency = -2})
local T1TweenR = TweenService:Create(text1, infoDoorR, {Transparency = -2})
local T2TweenR = TweenService:Create(text2, infoDoorR, {Transparency = -2})
script.Parent.ClickDetector.MouseClick:Connect(function()
if deb == false then
deb = true
buttonTween:Play()
doorTween:Play()
T1Tween:Play()
T2Tween:Play()
button.ClickDetector.MaxActivationDistance = 0
button.Sound:Play()
Ttext.Text = timer
wait(0.5)
door.CanCollide = false
wait(0.5)
button.PointLight.Range = 0
while true do
timerText = timerText - 1
Ttext.Text = timerText
task.wait(1)
end
wait(timer - 1)
buttonTweenR:Play()
doorTweenR:Play()
T1TweenR:Play()
T2TweenR:Play()
Ttext = " "
wait(0.5)
door.CanCollide = true
wait(0.5)
button.ClickDetector.MaxActivationDistance = 5
button.PointLight.Range = 20
deb = false
end
end)