如果声明在RobloxLua中不起作用

时间:2016-11-29 07:47:41

标签: lua roblox

大家好我想知道为什么这段代码会给我一个错误

 它应该收取所有玩家的一些现金,然后将1加到int值(阶段)更新其成本并更改速度值(SpawnDelay),这样当他再次点击它时,它知道他在哪个阶段但由于某种原因,这不起作用,因为if语句显示为不正确,请帮助:

local stage = script.Parent.stage.Value
local text = script.Parent.Text
script.Parent.MouseButton1Click:connect(function()
    if stage == 0 then
    for i, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Cash.Value = v.leaderstats.Cash.Value - 100 

workspace.RedTycoon.Factory.SpawnDelay.Value = 15
text = "Upgrade Speed            (Cost = 200)"
stage =  stage + 1

    elseif stage == 1 then

    for i, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Cash.Value = v.leaderstats.Cash.Value - 200 

workspace.RedTycoon.Factory.SpawnDelay.Value = 10
text = "Upgrade Speed            (Cost = 500)"
stage =  stage + 1
end
        elseif stage == 2 then

    for i, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Cash.Value = v.leaderstats.Cash.Value - 500 

workspace.RedTycoon.Factory.SpawnDelay.Value = 8

text = "Upgrade Speed            (Cost = 1000)"


stage =  stage + 1

end)

我刚试过这个

local stage = script.Parent.stage.Value
local text = script.Parent.Text
local delaytime = workspace.RedTycoon.Factory.SpawnDelay.Value
text = "Upgrade Speed            (Cost = 100)"
script.Parent.MouseButton1Click:connect(function()
if stage == 0 then

delaytime = 15
text = "Upgrade Speed            (Cost = 500)"
stage = stage + 1
for _, player in ipairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("leaderstats") then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 100
    end
end



elseif stage == 1 then
    delaytime = 10
text = "Upgrade Speed            (Cost = 1000)"
stage = stage + 1
for _, player in ipairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("leaderstats") then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 500
    end
end


elseif stage == 2 then
    delaytime = 10
    text = "Upgrade Speed            (Cost = 1500)"
stage = stage + 1
for _, player in ipairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("leaderstats") then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 1000
    end
end


elseif stage == 3 then
    text = "Upgrade Speed            (Cost = 2000)"
    delaytime = 8
stage = stage + 1
for _, player in ipairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("leaderstats") then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 1500
    end
end


elseif stage == 4 then
    delaytime = 4
    text = "Upgrade Speed            (Cost = 20000)"
stage = stage + 1
for _, player in ipairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("leaderstats") then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 2000
    end

end

elseif stage == 5 then
    delaytime = 2
    text = "No More Upgrades Avalible"  
stage = stage + 1
for _, player in ipairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("leaderstats") then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value -  20000
    end

end

else
    text = "Just for being annoying here you have 1 less cash:"

for _, player in ipairs(game.Players:GetPlayers()) do
    if player:FindFirstChild("leaderstats") then
           player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 1
        end

end
        wait(4)
        text = "No More Upgrades Avalible"  


        end

end)

没有工作

1 个答案:

答案 0 :(得分:1)

删除所有多余的代码语句后,我们可以看到代码结构至少缺少三个end个关键字。

script.Parent.MouseButton1Click:connect(function ()
    if stage == 0 then
        for i, v in pairs(game.Players:GetPlayers()) do
        -- missing end
    elseif stage == 1 then
        for i, v in pairs(game.Players:GetPlayers()) do

        end
    elseif stage == 2 then
        for i, v in pairs(game.Players:GetPlayers()) do
        -- missing end
    -- missing
end)