For循环失败

问题描述 投票:0回答:1

我一直在尝试制作Roblox剑斗游戏(我的第一个roblox游戏)。我在代码中发现了一些语法问题,但修复它们并不能解决此问题。我一直在检查我的代码,但似乎没有任何效果。这是代码的第15至83行,因为注释告诉我问题出在for循环之前(在第15行只是变量之前)

    --Game Loop

while true do

    Status.Value = "Waiting for enough players"

    repeat wait(1) until game.Players.NumPlayers >= 2

    Status.Value = "Intermission"

    wait(10)

    local plrs = {}

    for i, player in pairs(game.Players:GetPlayers()) do
        if player then  
            table.insert(plrs,player) -- Add each player into plrs table
        end
    end

    wait(2)

    local AvailableMaps = MapsFolder:GetChildren()

    local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]

    Status.Value = ChosenMap.Name.." Chosen"

    local ClonedMap = ChosenMap:Clone()
    ClonedMap.Parent = workspace

    --Teleport players to the map

    local SpawnPoints = ClonedMap:FindChild("SpawnPoints")

    if not SpawnPoints then
        print("Spawnpoints not found!")
    end

    local AvailableSpawnPoints = SpawnPoints:GetChildren

    for i, player in pairs(plrs) do
        if player then
            character = player.Character

            if character then
                -- Teleport them

                character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
                table.remove(AvailableSpawnPoints,1)


                -- Give them a Sword

                local Sword = ServerStorage.Sword:Clone()
                Sword.Parent = player.Backpack

                local GameTag = Instance.new("BoolValue")
                GameTag.Name = "GameTag"
                GameTag.Parent = player.Character

            else
                -- There is no character
                if not player then
                    table.remove(plrs,i)
                end
            end
        end
    end

这里是错误:19:30:03.021-ServerScriptService.Main脚本:56:预期为'(','{'或,为'for'帮助我帮助其他玩家

lua roblox
1个回答
0
投票

@ luther的评论绝对正确。 for循环正上方的行存在语法错误。 SpawnPoints:GetChildren是一个函数调用,您忘记添加括号了。

local AvailableSpawnPoints = SpawnPoints:GetChildren()
© www.soinside.com 2019 - 2024. All rights reserved.