Scope: local vs Global: Coding lesson for kids

In “Scope: local vs Global”, children learn about local score = 0, score = 0 -- no "local" (first use) and local x = 1 x = 2 -- no "local" here.

local score = 0: "local" creates a new variable that only exists inside the current block or function — the safe default.

score = 0 -- no "local" (first use): If "score" has NOT been declared with "local" anywhere above, this creates a GLOBAL — visible everywhere, which can cause surprise bugs.

local x = 1 x = 2 -- no "local" here: If "x" was already declared with "local" above, this UPDATES that same local — it does NOT create a global. "local" is only needed on the first line.

This lesson is part of Lua in Coding at Pearls Valley Academy — The language behind Roblox’s Luau.

Each lesson starts with a short narrated, animated explanation, then hands-on practice. A wrong answer gets a gentle hint, never a penalty, and children earn stars and pearls as they go.