Roblox Lua MouseButton1点击不工作

时间:2017-06-01 16:16:01

标签: lua roblox

以下是一些上下文,它们适用于TextButtons,但它们是在脚本中构建的。所以我构建它们但是如果我不在代码周围放置if语句,我会得到一个错误,说CL1是零。但是我知道CL1在整个代码中并不总是Nil,因为我在按钮显示之前分配它。我真的不确定如何解决它,我已经尝试了一切。任何意见都表示赞赏。

以下是代码:

if(CL1 ~= nil) then
CL1.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Center1Spawns
end)

CL2.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Center2Spawns
end)

CL3.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Center3Spawns
end)



RL1.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Right1Spawns
end)



RL2.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Right2Spawns
end)



RL3.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Right3Spawns
end)


LL1.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Left1Spawns
end)



LL2.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Left2Spawns
end)



LL3.MouseButton1Click:connect(function()
    spawnChosen = true
    spawnPicked = Left3Spawns
end)



VP1.MouseButton1Click:connect(function()
    print("Clicked!")
    spawnChosen = true
    spawnPicked = Victory1Spawns
end)


VP2.MouseButton1Click:connect(function()
    print("Clicked!")
    spawnChosen = true
    spawnPicked = Victory2Spawns
end)
end

1 个答案:

答案 0 :(得分:0)

1)检查以确保它不在另一个gui后面 2)如果单击不起作用,MouseButton1Down可能会 3)表格有时很有帮助

local Buttons = {VP2,VP1,LL3,LL2,LL1,RL3,RL2,RL1,CL3,CL2,CL1,}
local Spawns = {Victory2Spawns,Victory1Spawns,Left3Spawns,Left2Spawns,Left1Spawns,Right3Spawns,Right2Spawns,Right1Spawns,Center3Spawns,Center2Spawns,Center1Spawns,}

for i,v in ipairs(Buttons) do
    if not v:IsA"ImageButton" and not v:IsA"TextButton" then
        print("It's not a button")
    end
    v.MouseButton1Down:connect(function()
        print("Saw Mouse Button Down")
        spawnChosen = true
        spawnPicked = Spawns[i]
    end)
    v.MouseButton1Click:connect(function()
        print("Saw click")
        spawnChosen = true
        spawnPicked = Spawns[i]
    end)
end