0
votes

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

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.

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------------

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)
1
Please post the code that highlights the platforms. - Kylaaa
ok will do in a moment - Paul
Where does this LocalScript live? - Kylaaa
StarterCharacterScirpts - Paul

1 Answers

0
votes

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.