roblox - 如何在 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)
解决方案
我在我的游戏中创建了一个计时器,我将与您分享代码:
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
推荐阅读
- angular - Firestore/ionic 错误 - 调用 .map 时方法 snapshotChanges 返回未定义
- user-interface - javafx 按钮从 txt 读取行到文本字段
- ansible - 执行 MFA 政策后无法担任角色
- javascript - 如何将数组 json 插入到其他 const 的索引中?
- java - 从资源文件加载目录并将文件加载到列表中
- swift - 在 Swift 5.0 中从 AppDelegate 实例化窗口失败
- ruby-on-rails - 通过 Ruby on Rails 中的 HTTP 标头自定义授权
- terminal - 如何在两个终端之间通话,一个使用 Ncat,一个使用 Nping?
- ios - 点击segmentedControl时SwiftUI关闭键盘
- javascript - 使用变量反应动态导入不起作用