首页 > 解决方案 > 如何在 Roblox 中制作按钮计时器?

问题描述

我在 Roblox 中创建了一个 obby,我想制作一个玩家可以踩到的按钮,以使他们面前的平台坚固。我检查了文档,发现没有任何帮助。这是我的代码:(忽略 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)

标签: roblox

解决方案


我在我的游戏中创建了一个计时器,我将与您分享代码:

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

推荐阅读