本地脚本的部分代码随机停止在重生上工作 [英] Parts of code of local script randomly stop working on respawn

查看:80
本文介绍了本地脚本的部分代码随机停止在重生上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a question concerning a Roblox game. The game works fine until a character dies. Then, random parts of the local script stop working. It's too long to explain so here is a link to the game:

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

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

If you are interested, walk around the board and look at how the columns and the rows light up. It all works. Then, let your character die. You can do this either by falling of the edge of the board or by standing on an enemy's platform (if you are playing against someone). The easier way is just fall of the edge. When your character respawns, the platforms don't light up any more. This is very strange as it's literally just a chuck of the code that sits on the local script that stops working. Can anyone please explain why this is happening? tx

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

----UPDATE------

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

This seems to happen eminently when you are playing against someone and not on your own, so you would have to try it against someone or simulating many players on a local server.

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

Here is the huge function that I got to handle what happens when the player stands on a platform. Bear in mind this is practically the first page of working code I have written in Studio.

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

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

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

I have been trying a few things, which included moving the script to starterPlayerScripts (didn't solve the issue). I think there is an issue with the script maybe loading before the character is ready. Also, this doesn't happen when the character falls off an edge, it only happens when the character dies in 'on land', that is with all the body parts coming apart. Would this have an effect on the ability of Roblox to read the script properly?

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)

推荐答案

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

I'm not sure if it's the case, but check if the script respawns inside the character, if it doesn't put the script inside of StarterPlayerScripts, add some variables and you should be fine.

这篇关于本地脚本的部分代码随机停止在重生上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆