本地脚本的代码部分随机停止在重生上工作

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

我对Roblox游戏有疑问。游戏正常进行,直到角色死亡。然后,本地脚本的随机部分停止工作。解释时间太长,因此这里是游戏的链接:

https://web.roblox.com/games/4586742374/Times-Tables-Turf-War

[如果您有兴趣,请在黑板上四处走走,看看列和行如何点亮。一切正常。然后,让你的角色死亡。您可以通过跌倒棋盘边缘或站在敌人的平台上来完成此操作(如果您正在与某人对抗)。更简单的方法就是边缘崩溃。当您的角色重生时,平台不再点亮。这很奇怪,因为它实际上只是位于停止工作的本地脚本上的代码的一部分。谁能解释为什么会这样吗? tx

----更新------

[这似乎是在与某人对抗而不是独自对抗时发生的,因此您必须尝试与某人对抗或模拟本地服务器上的许多玩家。

这是我必须处理的巨大功能,当玩家站在平台上时会发生什么。请记住,这实际上是我在Studio中编写的working代码的第一页。

----- UPDATE2 ------------

我一直在尝试一些事情,包括将脚本移动到starterPlayerScripts(无法解决问题)。我认为脚本可能存在问题,可能在角色准备好之前就已加载。同样,当角色掉落边缘时不会发生这种情况,仅当角色在“陆地上”死亡时才会发生,即所有身体部位都分开。这会影响Roblox正确读取脚本的能力吗?

local hrp = char:WaitForChild("HumanoidRootPart")
game:GetService("RunService").Heartbeat:Connect(function()
    local charpos = hrp.Position
    for k, v in pairs (allParts) do
        if (charpos - v.CFrame.Position).magnitude <= 6 then -- this is what happens if the player is standing on the platform----------------------------------------------------------

            if findEnemyPlat(allPlats[k].Number) then -- if it's an enemy platform, deal damage
                    DealDamage()
            end

            --first grab information from the platform you are standing on
            local column = allPlats[k].Column
            local row =  allPlats[k].Row
            local number = allPlats[k].Number

            --this is what happens if plr standing in platfrom which number matches board
            if column *row  == game.Workspace.TargetNumber.Value then       
                if findAllPlats(allPlats[k].Number) or allPlats[k].Eliminated == true then -- do nothing if plat is scored, and return immediately if eliminated by you so to not score many points
                    return
                else
                    allPlats[k].Eliminated = true
                    points = points + 1
                    numIfScored:InvokeServer(column, row, teamColorReady, points, team, number)
                end
            end

--------------------------------------------------------------------------------------------------------------------------------------------------------
--What happens to the rest of the platforms and cubees when you stand on one platform-------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------

                for k, v in pairs(allPlats) do

--To platforms and Cubes on same COLUMN-----------------------------------------------------------------------------------------------------------------
                if v.Column == column then -- check which platforms are on the same column by comparing the column property of yours with each one
                    --To The Platforms:
                    v.Part.Transparency = 0
                    v.Part.Material = "Neon"
                    v.Part.BrickColor = BrickColor.new("Medium stone grey")

                --To The Cubes one side
                allCubesCol[allPlats[k].Column + 1].Size = Vector3.new(9.9,16,9.9)
                --and the numbers one side
                local model = allCubesCol[allPlats[k].Column + 1]:GetChildren() -- one side
                for k, v in pairs (model) do
                    v.Material = "Neon"
                end
                local green = allCubesCol[allPlats[k].Column + 1]:GetChildren()
                for k, v in pairs (green) do
                    local X = green[k].Position.X
                    local Y = green[k].Position.Y
                    local Z = green[k].Position.Z
                    green[k].Position = Vector3.new(X, 7, Z)
                end

                --To The Cubes other side
                allCubesCol2[allPlats[k].Column + 1].Size = Vector3.new(9.9,16,9.9)
                --and the numbers other side
                local model2 = allCubesCol2[allPlats[k].Column + 1]:GetChildren() -- the other side
                for k, v in pairs (model2) do
                    v.Material = "Neon"
                end
                local yellow = allCubesCol2[allPlats[k].Column + 1]:GetChildren()
                for k, v in pairs (yellow) do
                    local X = yellow[k].Position.X
                    local Y = yellow[k].Position.Y
                    local Z = yellow[k].Position.Z
                    yellow[k].Position = Vector3.new(X, 7, Z)
                end


--To platforms and Cubes on same ROW---------------------------------------------------------------------------------------------------------
                  elseif v.Row == row then -- check which platforms are on the same row by comparing the column property of yours with each one


                --To the Platforms
                v.Part.BrickColor = BrickColor.new("Medium stone grey")
                v.Part.Material = "Neon"
                v.Part.Transparency = 0

                --To the Cubes one side
                allCubesRow[allPlats[k].Row + 1].Transparency = .7
                allCubesRow[allPlats[k].Row + 1].Size = Vector3.new(9.9,16,9.9) 

                -- To the numbers one side
                local model = allCubesRow[allPlats[k].Row + 1]:GetChildren()
                for k, v in pairs (model) do
                    v.Material = "Neon"
                end
                local blue = allCubesRow[allPlats[k].Row + 1]:GetChildren()
                for k,v in pairs (blue) do
                    local X = blue[k].Position.X
                    local Y = blue[k].Position.Y
                    local Z = blue[k].Position.Z
                    blue[k].Position = Vector3.new(X, 7, Z)
                end

                --To the Cubes other side
                allCubesRow2[allPlats[k].Row + 1].Transparency = .7
                allCubesRow2[allPlats[k].Row + 1].Size = Vector3.new(9.9,16,9.9)    

                -- To the numbers other side
                local model2 = allCubesRow2[allPlats[k].Row + 1]:GetChildren()
                for k, v in pairs (model2) do
                    v.Material = "Neon"
                end
                local red = allCubesRow2[allPlats[k].Row + 1]:GetChildren()
                for k,v in pairs (red) do
                    local X = red[k].Position.X
                    local Y = red[k].Position.Y
                    local Z = red[k].Position.Z
                    red[k].Position = Vector3.new(X, 7, Z)
                end
            end
        end

        return  
    else

--------------------------------------------------------------------------

    ----------------------------------------------------------------------
    --

 this is what happens to ALL PLATFROMS and CUBES the player is not on a platform ----------------------------------------------------------------------
    ------------------------------------------------------------------------------------------------------------------------------------------------    


        --Platforms

        v.Material = "Glass" -- restore material
        v.BrickColor = BrickColor.new("Black") -- restore color

        if allPlats[k].Number == findAllPlats(allPlats[k].Number) then -- except if it belongs to a scored platform
                    v.BrickColor = findAllPlatsColor(allPlats[k].Number)
                    v.Material = "Neon"
        end

        --Cubes

        allCubesCol[allPlats[k].Column + 1].Size = Vector3.new(9.9,9.9,9.9) -- restore size
        allCubesCol2[allPlats[k].Column + 1].Size = Vector3.new(9.9,9.9,9.9)
        allCubesRow[allPlats[k].Row + 1].Size = Vector3.new(9.9,9.9,9.9)
        allCubesRow2[allPlats[k].Row + 1].Size = Vector3.new(9.9,9.9,9.9)

        --Numbers

        --green side
            local model = allCubesCol[allPlats[k].Column + 1]:GetChildren() -- restore color and material
                for k, v in pairs (model) do
                    v.BrickColor = BrickColor.new("Ghost grey")
                    v.Material = "Glass"
                end

        --blue side
            local model2 = allCubesRow[allPlats[k].Row + 1]:GetChildren()
                for k, v in pairs (model2) do

                    v.BrickColor = BrickColor.new("Ghost grey")
                    v.Material = "Glass"
                end

        --yellow side
                local model3 = allCubesCol2[allPlats[k].Column + 1]:GetChildren()
                for k, v in pairs (model3) do
                    v.BrickColor = BrickColor.new("Ghost grey")
                    v.Material = "Glass"
                end

        --red side
                local model4 = allCubesRow2[allPlats[k].Row + 1]:GetChildren()
                for k, v in pairs (model4) do
                    v.BrickColor = BrickColor.new("Ghost grey")
                    v.Material = "Glass"
                end


        local green = allCubesCol[allPlats[k].Column + 1]:GetChildren() -- restores position
                for k, v in pairs (green) do
                    local X = green[k].Position.X
                    local Y = green[k].Position.Y
                    local Z = green[k].Position.Z
                    green[k].Position = Vector3.new(X, 5, Z)
                end 

        local blue = allCubesRow[allPlats[k].Row + 1]:GetChildren()
                for k, v in pairs (blue) do
                    local X = blue[k].Position.X
                    local Y = blue[k].Position.Y
                    local Z = blue[k].Position.Z
                    blue[k].Position = Vector3.new(X, 5, Z)
                end


        local yellow = allCubesCol2[allPlats[k].Column + 1]:GetChildren()
                for k, v in pairs (yellow) do
                    local X = yellow[k].Position.X
                    local Y = yellow[k].Position.Y
                    local Z = yellow[k].Position.Z
                    yellow[k].Position = Vector3.new(X, 5, Z)
                end
        local red = allCubesRow2[allPlats[k].Row + 1]:GetChildren()
                for k, v in pairs (red) do
                    local X = red[k].Position.X
                    local Y = red[k].Position.Y
                    local Z = red[k].Position.Z
                    red[k].Position = Vector3.new(X, 5, Z)
                end
    end
end
end)
lua local local-variables roblox
1个回答
0
投票

我不确定是否是这种情况,但是请检查脚本是否在角色内部重生,如果没有将脚本放入StarterPlayerScripts内,请添加一些变量,您应该没事。

© www.soinside.com 2019 - 2024. All rights reserved.