在roblox工作室中,我想制作一个按钮,该按钮会在游戏节目中的某种迷你游戏上在某个塔上爆炸,所以我编写了此代码,但由于某种原因该代码无法正常工作。如果我也能得到可靠的答复,将不胜感激!
脚本:
local ClickDetector = script.Parent
ClickDetector.MaxActivationDistance = 10
ClickDetector.MouseClick:Connect(function()
local Towers = workspace.Towers
local BT = math.random(1,8)
local BT2 = BT
wait(0.2)
if BT2 == "1" then
local boom = Instance.new("Explosion")
boom.Position = Towers.Black.boompart.Position
boom.Parent = workspace
elseif
BT2 == "2" then
local boom = Instance.new("Explosion")
boom.Position = Towers.White.boompart.Position
boom.Parent = workspace
elseif
BT2 == "3" then
local boom = Instance.new("Explosion")
boom.Position = Towers.Blue.boompart.Position
boom.Parent = workspace
elseif
BT2 == "4" then
local boom = Instance.new("Explosion")
boom.Position = Towers.Brown.boompart.Position
boom.Parent = workspace
elseif
BT2 == "5" then
local boom = Instance.new("Explosion")
boom.Position = Towers.Green.boompart.Position
boom.Parent = workspace
elseif
BT2 == "6" then
local boom = Instance.new("Explosion")
boom.Position = Towers.Red.boompart.Position
boom.Parent = workspace
elseif
BT2 == "7" then
local boom = Instance.new("Explosion")
boom.Position = Towers.Pink.boompart.Position
boom.Parent = workspace
elseif
BT2 == "8" then
local boom = Instance.new("Explosion")
boom.Position = Towers.Yellow.boompart.Position
boom.Parent = workspace
end
print(BT2)
end)
答案 0 :(得分:1)
我可能会更改此行
if BT2 == "1" then
到
if BT2 == 1 then
这里的“ 1”是一个字符串,因为它在引号内。在这种情况下,BT2是一个数字。它们存储为两种不同的数据类型。因此,它们不相等。
注意,如果您尝试:
print(“ 1” == 1)
输出为: 错误
请参阅文档中的最后一句话:https://www.lua.org/pil/3.2.html