Как мне сделать кнопочный таймер в Roblox?

Я создавал обби в Roblox, и я хотел сделать кнопку, на которую игрок мог бы наступить, чтобы платформы перед ними были прочными. Я проверил документацию и не нашел ничего, что могло бы помочь. Вот мой код: (Игнорируйте e, ee, eee, bt, bt1, bt2 и tch. Это мои части / переменные / имена функций)

bt = game.Workspace.e.SurfaceGui.ButtonTimer
bt1 = game.Workspace.ee.SurfaceGui.ButtonTimer1
bt2 = game.Workspace.eee.SurfaceGui.ButtonTimer2

bt.Text = "hi "
bt1.Text = "hi "
bt2.Text = "hi "

script.Parent.Touched:Connect(function(tch)
    if tch.Parent:FindFirstChild("Humanoid") then
        game.Workspace.e.Transparency = 0
        game.Workspace.e.CanCollide = true
        game.Workspace.ee.Transparency = 0
        game.Workspace.ee.CanCollide = true
        game.Workspace.eee.Transparency = 0
        game.Workspace.eee.CanCollide = true
        bt.Text = "10"
        bt1.Text = "10"
        bt2.Text = "10"
        wait(1)
        bt.Text = "9"
        bt1.Text = "9"
        bt2.Text = "9"
        wait(1)
        bt.Text = "8"
        bt1.Text = "8"
        bt2.Text = "8"
        wait(1)
        bt.Text = "7"
        bt1.Text = "7"
        bt2.Text = "7"
        wait(1)
        bt.Text = "6"
        bt1.Text = "6"
        bt2.Text = "6"
        wait(1)
        bt.Text = "5"
        bt1.Text = "5"
        bt2.Text = "5"
        wait(1)
        bt.Text = "4"
        bt1.Text = "4"
        bt2.Text = "4"
        wait(1)
        bt.Text = "3"
        bt1.Text = "3"
        bt2.Text = "3"
        wait(1)
        bt.Text = "2"
        bt1.Text = "2"
        bt2.Text = "2"
        wait(1)
        bt.Text = "1"
        bt1.Text = "1"
        bt2.Text = "1"
        wait(1)
        bt.Text = "0"
        bt1.Text = "0"
        bt2.Text = "0"
        game.Workspace.e.Transparency = 0.75
        game.Workspace.e.CanCollide = false
        game.Workspace.ee.Transparency = 0.75
        game.Workspace.ee.CanCollide = false
        game.Workspace.eee.Transparency = 0.75
        game.Workspace.eee.CanCollide = false
    else 
        game.Workspace.e.BrickColor = BrickColor.Red()
    end
end)

person Jonathan Bachmeier    schedule 27.11.2020    source источник
comment
Есть ли что-нибудь в этом коде, что не работает? Или вы ищете способ очистить свой код чем-нибудь более официальным? Функция wait(), которую вы уже используете, возвращает текущий поток, поэтому это один из способов заставить работать функцию, подобную таймеру.   -  person Kylaaa    schedule 27.11.2020
comment
Код не работает. Я почти уверен, что определение bt, bt1 и bt2 - это то место, где код не работает.   -  person Jonathan Bachmeier    schedule 28.11.2020


Ответы (1)


Я создал в своей игре таймер, поделюсь с вами кодом:

local timer = script.Parent
local minutes = 1
local seconds = 9

local adm = script.Parent.Parent

repeat
    if seconds <= 0 then
        minutes = minutes - 1
        seconds = 59
    else
        seconds = seconds - 1
    end
    if seconds <= 9  then
        timer.Text = "Vote time: "..tostring(minutes)..":0"..tostring(seconds)
    else
        timer.Text = "Vote time: "..tostring(minutes)..":"..tostring(seconds)
    end
    wait(1)
until minutes <= 0 and seconds <= 0
person Matthew    schedule 07.01.2021