Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do i fix this script on changing block colors?

Asked by 7 years ago

I Am Tyring to make a parkour map that the colors of some blocks that change, but i am also using to "while true do" things, and it only chooses one to do? Please help, im new to scripting and am eager to learn!!! <MY SCRIPT: please ask if u need more details!

local Part1 = game.Workspace.FancyJumpParts.Part1 local Block1 = game.Workspace.JumpBlocks.Block1

while true do Block1.BrickColor = BrickColor.Green() wait(3) Block1.BrickColor = BrickColor.Yellow() wait(3) Block1.BrickColor = BrickColor.Black() wait(3) Block1.BrickColor = BrickColor.Random() wait(3) end

while true do Part1.BrickColor = BrickColor.Red() Part1.CanCollide = false wait(5) Part1.BrickColor = BrickColor.Blue() Part1.CanCollide = true wait(5)

end

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Please use a code block in the future

With using a code block, your code looks like this,

local Part1 = game.Workspace.FancyJumpParts.Part1 
local Block1 = game.Workspace.JumpBlocks.Block1

while true do 
    Block1.BrickColor = BrickColor.Green() 
    wait(3) 
    Block1.BrickColor = BrickColor.Yellow() 
    wait(3) 
    Block1.BrickColor = BrickColor.Black() 
    wait(3) 
    Block1.BrickColor = BrickColor.Random() 
    wait(3) 
end

while true do 
    Part1.BrickColor = BrickColor.Red() 
    Part1.CanCollide = false 
    wait(5)
    Part1.BrickColor = BrickColor.Blue() 
    Part1.CanCollide = true 
    wait(5)
end

The problem,

Lua can only do one thing at a time, and it reads from top to bottom, mainly. Once the code reaches the first loop, it never sees the other one. It never breaks out.

There are multiple ways of fixing this, but since you want specific timings, I would suggest the simplest solution by using the spawn function.

This will allow your code to see both loops and deal with them accordingly.

local Part1 = game.Workspace.FancyJumpParts.Part1 
local Block1 = game.Workspace.JumpBlocks.Block1

spawn(function()
    while true do
        Block1.BrickColor = BrickColor.Green() 
        wait(3) 
        Block1.BrickColor = BrickColor.Yellow() 
        wait(3) 
        Block1.BrickColor = BrickColor.Black() 
        wait(3) 
        Block1.BrickColor = BrickColor.Random() 
        wait(3) 
    end
end)

while true do 
    Part1.BrickColor = BrickColor.Red() 
    Part1.CanCollide = false 
    wait(5)
    Part1.BrickColor = BrickColor.Blue() 
    Part1.CanCollide = true 
    wait(5)
end

Good Luck!

If I helped, please don't forget to accept my answer.
Ad

Answer this question