Blocks to Lua: the same script two ways - Newly guides

Build a touch script with blocks, flip to Luau to see the code it makes, then change one line by hand.

Two ways to say the same thing

Every block script is really a Luau script underneath. Today you'll build with blocks, look at the Luau it makes, and then edit the Luau yourself.

1. Build it with blocks

Add a part. Select it, open Script, choose Blocks, and build:

  1. When a player touches this
  2. Repeat 3 times, and inside it:

- Paint this (pick a colour)
- Wait 1 seconds
- Paint this (a different colour)
- Wait 1 seconds

  1. after the repeat: Show "Done!" on screen for 2 seconds

Play it. The part blinks three times when you touch it.

2. Flip to Luau

At the top of the block editor, switch to the Luau tab. That's the code your blocks made. Find:

local busy1 = false
this.Touched:Connect(function(other)
	if busy1 or not other:IsA("Player") then return end
	busy1 = true
	for _ = 1, 3 do
		this.Color = Color3.fromHex("#ff6b6b")
		task.wait(1)
		this.Color = Color3.fromHex("#7fe6d6")
		task.wait(1)
	end
	say("Done!", 2)
	busy1 = false
end)

3. Edit the Luau

Copy the code. Add a real Script to the part (Add → Script), paste it in, and delete the block script. Now change things no block offers:

```luau
local touches = 0
-- inside the function, after busy1 = true:
touches += 1
say("Touched " .. touches .. " times", 2)
```

Done when

Open on Newly