Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i fix this script on changing block colors?

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.