This commit is contained in:
listik committed 2026-11-16 23:50:40 +03:00
commit 2d6a8a867d
1093 files changed
+2424571

No files matched your search

+780
View File
@@ -0,0 +1,780 @@
-- TutorialGuide (LocalScript, StarterPlayerScripts): the first-time tutorial. Runs once per player (attribute
-- TutorialDone from OrnamentPlayerData; "Done" goes to the server through the Tutorial remote).
-- It never changes the other UI scripts: it watches the windows of OrnamentCraftGui and puts its own layer on top.
-- spotlight : the screen is dimmed and blocked except a "hole" around one element (gold pulsing ring + hand +
-- a speech bubble). Either the bubble has a "Дальше" button (the hole is blocked too) or the player must
-- press the element itself (the hole lets clicks through) and the step waits for the result.
-- walk : glowing chevrons on the ground lead to the generator / shredder, a sign floats over the target, a
-- banner says what to do; the HUD buttons are blocked.
-- Flow: welcome -> balance -> level -> walk to the generator -> generator window (grid, drops, booster, Автоузор,
-- Создать) -> the first toy -> walk to the shredder -> shredder window (pick the toy, Переработать) -> shards back
-- -> shop button -> shop window -> close -> done. "Пропустить" (top right) ends it at any time.
-- If a window is closed in the middle (E, walking away), the tutorial goes back to the walk step of that machine.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local folder = ReplicatedStorage:WaitForChild("OrnamentMachine")
local Config = require(folder:WaitForChild("Config"))
local tutorialRemote = folder:WaitForChild("Tutorial", 30)
local K = require(player:WaitForChild("PlayerScripts"):WaitForChild("OrnamentCraftUI"):WaitForChild("ShopKit"))
---------------------------------------------------------------- start conditions
do
local t = os.clock()
while not player:GetAttribute("DataLoaded") and os.clock() - t < 60 do task.wait(0.2) end
end
-- already done: wait — an admin can reset it (TutorialDone -> false), then it starts right away
while player:GetAttribute("TutorialDone") do player:GetAttributeChangedSignal("TutorialDone"):Wait() end
local playerGui = player:WaitForChild("PlayerGui")
local gui = playerGui:WaitForChild("OrnamentCraftGui", 30)
if not gui then return end
-- wait for the opening camera shot (IntroCamera sets the local attribute IntroDone at its end)
do
local t = os.clock()
while player:GetAttribute("IntroDone") ~= true and os.clock() - t < 60 do task.wait(0.1) end
end
task.wait(0.4)
local GOLD = Color3.fromRGB(255, 205, 70)
local NAVY = Color3.fromRGB(14, 32, 52)
local WHITE = Color3.new(1, 1, 1)
local SOFT = Color3.fromRGB(200, 225, 235)
local TOUCH = UIS.TouchEnabled and not UIS.KeyboardEnabled
local OPEN_HINT = TOUCH and "press the “Open” button at the machine" or "press E"
local function new(class, props, children)
local o = Instance.new(class)
if o:IsA("GuiButton") then o:SetAttribute("UXDone", true) end -- OrnamentUX must not restyle / re-anchor them
for k, v in props or {} do if k ~= "Parent" then o[k] = v end end
for _, c in children or {} do c.Parent = o end
if props and props.Parent then o.Parent = props.Parent end
return o
end
local function tween(o, t, props, style)
local tw = TweenService:Create(o, TweenInfo.new(t, style or Enum.EasingStyle.Quad, Enum.EasingDirection.Out), props)
tw:Play()
return tw
end
---------------------------------------------------------------- the player's machine
local function myMachine()
local idx = player:GetAttribute("PlotIndex")
local zone = idx and workspace:FindFirstChild("Zones") and workspace.Zones:FindFirstChild("Zone_" .. idx)
return zone and zone:FindFirstChild("OrnamentMachine"), zone and zone:FindFirstChild("Plot")
end
local function hrp()
return player.Character and player.Character:FindFirstChild("HumanoidRootPart")
end
---------------------------------------------------------------- freeze the character (while a window is explained)
local saved
local function freeze(on)
local h = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
if not h then return end
if on and not saved then
saved = { h, h.WalkSpeed, h.JumpPower, h.JumpHeight }
h.WalkSpeed, h.JumpPower, h.JumpHeight = 0, 0, 0
elseif not on and saved then
if saved[1].Parent then saved[1].WalkSpeed, saved[1].JumpPower, saved[1].JumpHeight = saved[2], saved[3], saved[4] end
saved = nil
end
end
---------------------------------------------------------------- overlay
local tg = new("ScreenGui", { Name = "TutorialGui", IgnoreGuiInset = true, DisplayOrder = 50, ResetOnSpawn = false,
ZIndexBehavior = Enum.ZIndexBehavior.Sibling, Parent = playerGui })
local DIM = 0.42
local function blocker(transp)
local b = new("TextButton", { Text = "", AutoButtonColor = false, BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = transp,
BorderSizePixel = 0, Visible = false, ZIndex = 1 })
b:SetAttribute("NoSound", true) -- UISounds: the dark walls only swallow clicks, they are not buttons
b.Parent = tg
return b
end
local walls = { blocker(DIM), blocker(DIM), blocker(DIM), blocker(DIM) } -- around the hole
local holeCover = blocker(1) -- over the hole when it must not be pressed
local hudBlock = { blocker(0.55), blocker(0.55), blocker(0.55) } -- walk mode: HUD buttons
for _, b in hudBlock do new("UICorner", { CornerRadius = UDim.new(0, 18), Parent = b }) end
local ring = new("Frame", { BackgroundTransparency = 1, Visible = false, ZIndex = 3, Parent = tg }, {
new("UICorner", { CornerRadius = UDim.new(0, 16) }),
})
local ringStroke = new("UIStroke", { Color = GOLD, Thickness = 4, Parent = ring })
local hand = new("TextLabel", { BackgroundTransparency = 1, Text = "👆", TextSize = 54, Size = UDim2.fromOffset(70, 70), AnchorPoint = Vector2.new(0.5, 0.5),
Visible = false, ZIndex = 6, Parent = tg })
-- speech bubble
local bubble = new("Frame", { Name = "Bubble", BackgroundColor3 = NAVY, BackgroundTransparency = 0.04, Size = UDim2.fromOffset(470, 0),
AutomaticSize = Enum.AutomaticSize.Y, Visible = false, ZIndex = 4, Parent = tg }, {
new("UICorner", { CornerRadius = UDim.new(0, 22) }),
new("UIStroke", { Color = GOLD, Thickness = 3 }),
new("UIPadding", { PaddingTop = UDim.new(0, 16), PaddingBottom = UDim.new(0, 16), PaddingLeft = UDim.new(0, 18), PaddingRight = UDim.new(0, 18) }),
new("UIListLayout", { Padding = UDim.new(0, 12), SortOrder = Enum.SortOrder.LayoutOrder, HorizontalAlignment = Enum.HorizontalAlignment.Center }),
})
local bubbleScale = new("UIScale", { Parent = bubble })
local stepLabel = new("TextLabel", { BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 22), FontFace = K.FONT, TextSize = 18, TextColor3 = GOLD,
TextXAlignment = Enum.TextXAlignment.Left, LayoutOrder = 0, ZIndex = 5, Parent = bubble })
local bubbleText = new("TextLabel", { BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 0), AutomaticSize = Enum.AutomaticSize.Y, TextWrapped = true, RichText = true,
FontFace = K.FONT, TextSize = 25, TextColor3 = WHITE, TextXAlignment = Enum.TextXAlignment.Left, LayoutOrder = 1, ZIndex = 5, Parent = bubble }, {
new("UIStroke", { Color = Color3.fromRGB(8, 14, 24), Thickness = 1.5 }),
})
local btnRow = new("Frame", { Name = "TutButtons", BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 74), LayoutOrder = 2, ZIndex = 5, Visible = false, Parent = bubble })
-- walk banner
local banner = new("Frame", { BackgroundColor3 = NAVY, BackgroundTransparency = 0.08, AnchorPoint = Vector2.new(0.5, 0), Size = UDim2.fromOffset(560, 0),
AutomaticSize = Enum.AutomaticSize.Y, Visible = false, ZIndex = 4, Parent = tg }, {
new("UICorner", { CornerRadius = UDim.new(0, 20) }),
new("UIStroke", { Color = GOLD, Thickness = 3 }),
new("UIPadding", { PaddingTop = UDim.new(0, 12), PaddingBottom = UDim.new(0, 12), PaddingLeft = UDim.new(0, 18), PaddingRight = UDim.new(0, 18) }),
})
local bannerScale = new("UIScale", { Parent = banner })
local bannerText = new("TextLabel", { BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 0), AutomaticSize = Enum.AutomaticSize.Y, TextWrapped = true, RichText = true,
FontFace = K.FONT, TextSize = 26, TextColor3 = WHITE, ZIndex = 5, Parent = banner }, { new("UIStroke", { Color = Color3.fromRGB(8, 14, 24), Thickness = 1.5 }) })
-- skip
local skipBtn = new("TextButton", { Name = "SkipTutorial", Text = "Skip tutorial", FontFace = K.FONT, TextSize = 18, TextColor3 = WHITE, AutoButtonColor = true,
BackgroundColor3 = Color3.fromRGB(60, 70, 84), BackgroundTransparency = 0.25, AnchorPoint = Vector2.new(1, 1), Size = UDim2.fromOffset(210, 38), ZIndex = 8, Parent = tg }, {
new("UICorner", { CornerRadius = UDim.new(0.5, 0) }),
new("UIStroke", { Color = Color3.fromRGB(200, 210, 220), Thickness = 1.5, Transparency = 0.4, ApplyStrokeMode = Enum.ApplyStrokeMode.Border }),
})
---------------------------------------------------------------- state + layout (every frame)
local S = { mode = "none", target = nil, interactive = false, below = true }
local function screenRect(obj)
if not obj or not obj.Parent then return nil end
local sg = obj:FindFirstAncestorOfClass("ScreenGui")
local off = (sg and not sg.IgnoreGuiInset) and GuiService:GetGuiInset() or Vector2.zero
local p, s = obj.AbsolutePosition + off, obj.AbsoluteSize
if s.X < 2 or s.Y < 2 then return nil end
return p, s
end
local function visibleChain(obj)
local o = obj
while o and not o:IsA("ScreenGui") do
if o:IsA("GuiObject") and not o.Visible then return false end
o = o.Parent
end
return o ~= nil and o.Enabled
end
local function hudParts()
local hud = gui:FindFirstChild("Hud")
if not hud then return {} end
local list = {}
for _, n in { "Status", "Menu", "MenuRight" } do
local f = hud:FindFirstChild(n)
if f and f.Visible then table.insert(list, f) end
end
return list
end
local layoutConn
layoutConn = RunService.RenderStepped:Connect(function()
local scr = tg.AbsoluteSize
local ui = math.clamp(math.min(scr.X / 1100, scr.Y / 700), 0.62, 1.15)
local inset = GuiService:GetGuiInset()
local t = os.clock()
bubbleScale.Scale, bannerScale.Scale = ui, ui
-- bottom right corner: the windows have their close button top right, the HUD sits on the left
skipBtn.Position = UDim2.fromOffset(scr.X - 10, scr.Y - 10)
skipBtn.Size = UDim2.fromOffset(210 * ui, 38 * ui)
skipBtn.TextSize = math.floor(18 * ui)
local spot = S.mode == "spot"
local card = S.mode == "card"
local walk = S.mode == "walk"
-- hole
local p, s
if spot and S.target then
local obj = S.target()
if obj and visibleChain(obj) then p, s = screenRect(obj) end
end
if p then
local pad = 8
p, s = p - Vector2.new(pad, pad), s + Vector2.new(pad * 2, pad * 2)
end
local blocking = spot or card
for _, w in walls do w.Visible = blocking end
if blocking then
if p then
-- whole pixels, otherwise thin light seams show between the dark walls
local x, y = math.floor(p.X), math.floor(p.Y)
local w, h = math.ceil(p.X + s.X) - x, math.ceil(p.Y + s.Y) - y
p, s = Vector2.new(x, y), Vector2.new(w, h)
walls[1].Position, walls[1].Size = UDim2.fromOffset(0, 0), UDim2.fromOffset(scr.X, math.max(0, y))
walls[2].Position, walls[2].Size = UDim2.fromOffset(0, y + h), UDim2.fromOffset(scr.X, math.max(0, scr.Y - y - h))
walls[3].Position, walls[3].Size = UDim2.fromOffset(0, y), UDim2.fromOffset(math.max(0, x), h)
walls[4].Position, walls[4].Size = UDim2.fromOffset(x + w, y), UDim2.fromOffset(math.max(0, scr.X - x - w), h)
else
walls[1].Position, walls[1].Size = UDim2.fromOffset(0, 0), UDim2.fromOffset(scr.X, scr.Y)
for i = 2, 4 do walls[i].Size = UDim2.fromOffset(0, 0) end
end
end
holeCover.Visible = spot and p ~= nil and not S.interactive
if holeCover.Visible then holeCover.Position, holeCover.Size = UDim2.fromOffset(p.X, p.Y), UDim2.fromOffset(s.X, s.Y) end
ring.Visible = p ~= nil
if p then
local grow = 3 + 3 * math.sin(t * 5)
ring.Position = UDim2.fromOffset(p.X - grow, p.Y - grow)
ring.Size = UDim2.fromOffset(s.X + grow * 2, s.Y + grow * 2)
ringStroke.Transparency = 0.15 + 0.25 * (0.5 + 0.5 * math.sin(t * 5))
end
-- bubble
bubble.Visible = spot or card
if bubble.Visible then
local bs = bubble.AbsoluteSize -- already scaled
local bx, by
if p then
local cx = p.X + s.X / 2
bx = math.clamp(cx - bs.X / 2, 10, scr.X - bs.X - 10)
local gap = 70 * ui
local spaceBelow = scr.Y - (p.Y + s.Y)
if spaceBelow >= bs.Y + gap + 10 then
by, S.below = p.Y + s.Y + gap, true
elseif p.Y >= bs.Y + gap + 10 then
by, S.below = p.Y - gap - bs.Y, false
else
-- no room above / below: beside the element
S.below = nil
by = math.clamp(p.Y + s.Y / 2 - bs.Y / 2, 10, scr.Y - bs.Y - 10)
if p.X + s.X + bs.X + 30 < scr.X then bx = p.X + s.X + 24 else bx = math.max(10, p.X - bs.X - 24) end
end
-- the hand points at the element
hand.Visible = true
hand.TextSize = math.floor(54 * ui)
local bob = 8 * math.sin(t * 6)
if S.below == false then
hand.Text = "👇"
hand.Position = UDim2.fromOffset(cx, p.Y - 32 * ui - bob)
elseif S.below == true then
hand.Text = "👆"
hand.Position = UDim2.fromOffset(cx, p.Y + s.Y + 32 * ui + bob)
else
hand.Visible = false
end
else
hand.Visible = false
bx, by = scr.X / 2 - bs.X / 2, scr.Y / 2 - bs.Y / 2
end
bubble.Position = UDim2.fromOffset(bx, by)
else
hand.Visible = false
end
-- walk mode: banner + HUD blocked
banner.Visible = walk and bannerText.Text ~= ""
banner.Position = UDim2.fromOffset(scr.X / 2, inset.Y + 12)
local parts = walk and hudParts() or {}
for i, b in hudBlock do
local f = parts[i]
local pp, ss
if f then pp, ss = screenRect(f) end
b.Visible = pp ~= nil
if pp then b.Position, b.Size = UDim2.fromOffset(pp.X - 4, pp.Y - 4), UDim2.fromOffset(ss.X + 8, ss.Y + 8) end
end
end)
---------------------------------------------------------------- flow helpers
local skipped = false
local SKIP = {}
local function check() if skipped then error(SKIP) end end
local function waitUntil(cond, lost, timeout)
local t0 = os.clock()
while true do
check()
if cond() then return "ok" end
if lost and lost() then return "lost" end
if timeout and os.clock() - t0 > timeout then return "timeout" end
RunService.Heartbeat:Wait()
end
end
local pillObjs = {}
local function setButtons(list)
for _, c in btnRow:GetChildren() do c:Destroy() end
pillObjs = {}
btnRow.Visible = list ~= nil and #list > 0
if not btnRow.Visible then return end
local n = #list
local w = n == 1 and 260 or 200
local total = n * w + (n - 1) * 14
local x0 = (434 - total) / 2
for i, b in list do
local o = K.pill(btnRow, { Name = "TutBtn" .. i, Position = UDim2.fromOffset(x0 + (i - 1) * (w + 14), 2), Size = UDim2.fromOffset(w, 70), ZIndex = 6, TextMax = 28 }, b.fn)
o.set(b.kind or "ready", b.text)
table.insert(pillObjs, o)
end
end
local stepNo, STEPS = 0, 9
local function setStep(n) stepNo = n end
local function header() stepLabel.Text = stepNo > 0 and ("TUTORIAL · step " .. stepNo .. " of " .. STEPS) or "TUTORIAL" end
-- shows a bubble; returns when the button is pressed / the condition is met
-- target : function -> GuiObject (nil = centred card, the whole screen blocked)
-- opts.next: caption of the "Дальше" button opts.cond: wait for this instead (the element can be pressed)
-- opts.lost: returns "lost" when this becomes true
local function say(target, text, opts)
opts = opts or {}
check()
header()
bubbleText.Text = text
S.target = target
S.mode = target and "spot" or "card"
S.interactive = opts.cond ~= nil
local pressed = nil
if opts.buttons then
local list = {}
for _, b in opts.buttons do table.insert(list, { text = b.text, kind = b.kind, fn = function() pressed = b.id end }) end
setButtons(list)
elseif opts.cond then
setButtons(nil)
else
setButtons({ { text = opts.next or "Next", fn = function() pressed = "next" end } })
end
-- pop-in
bubble.Size = UDim2.fromOffset(470, 0)
local r
if opts.cond then
r = waitUntil(opts.cond, opts.lost, opts.timeout)
else
r = waitUntil(function() return pressed ~= nil end, opts.lost)
if r == "ok" then r = pressed end
end
return r
end
local function walkMode(text)
S.mode = "walk"
S.target = nil
bannerText.Text = text
end
---------------------------------------------------------------- ground markers
local markerFolder = new("Folder", { Name = "TutorialMarkers", Parent = workspace })
local markers = {}
local targetFx = {}
local function clearMarkers()
for _, m in markers do for _, p in m.parts do p:Destroy() end end
markers = {}
end
local function clearTarget()
for _, o in targetFx do o:Destroy() end
targetFx = {}
clearMarkers()
end
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
local function groundAt(pos)
local ignore = { markerFolder }
if player.Character then table.insert(ignore, player.Character) end
rayParams.FilterDescendantsInstances = ignore
local hit = workspace:Raycast(Vector3.new(pos.X, pos.Y + 20, pos.Z), Vector3.new(0, -60, 0), rayParams)
return hit and hit.Position.Y or pos.Y
end
local function part(props)
local p = Instance.new("Part")
p.Anchored, p.CanCollide, p.CanQuery, p.CanTouch, p.CastShadow = true, false, false, false, false
p.Material = Enum.Material.Neon
p.Color = GOLD
for k, v in props do p[k] = v end
p.Parent = markerFolder
return p
end
local function chevron(pos, dir)
local y = groundAt(pos) + 0.08
local tip = Vector3.new(pos.X, y, pos.Z) + dir * 0.7
local parts = {}
for _, a in { math.rad(140), math.rad(-140) } do
local armDir = CFrame.Angles(0, a, 0):VectorToWorldSpace(dir)
local center = tip + armDir * 0.75
table.insert(parts, part({ Size = Vector3.new(0.38, 0.08, 1.6), CFrame = CFrame.lookAt(center, center + armDir) }))
end
return { parts = parts }
end
local function buildPath(points)
clearMarkers()
local idx = 0
local carry = 2.2 -- the first chevron a bit in front of the player
for i = 1, #points - 1 do
local a = Vector3.new(points[i].X, 0, points[i].Z)
local b = Vector3.new(points[i + 1].X, 0, points[i + 1].Z)
local seg = b - a
local len = seg.Magnitude
if len > 0.1 then
local dir = seg.Unit
local d = carry
while d < len - 0.5 do
idx += 1
local pos = a + dir * d
local m = chevron(Vector3.new(pos.X, points[i].Y, pos.Z), dir)
m.index = idx
table.insert(markers, m)
d += 2.6
end
carry = d - len
end
end
end
-- running light along the chevrons, towards the target
local markerConn = RunService.Heartbeat:Connect(function()
local t = os.clock()
for _, m in markers do
local wave = (t * 1.6 - m.index * 0.12) % 1
local tr = 0.05 + 0.6 * wave
for _, p in m.parts do p.Transparency = tr end
end
end)
-- big pulsing ring on the ground at the target + a floating sign
local function showTarget(anchorPart, stand, title)
clearTarget()
local y = groundAt(stand) + 0.06
local disc = part({ Shape = Enum.PartType.Cylinder, Size = Vector3.new(0.1, 6, 6), Transparency = 0.45,
CFrame = CFrame.new(stand.X, y, stand.Z) * CFrame.Angles(0, 0, math.rad(90)) })
table.insert(targetFx, disc)
task.spawn(function()
while disc.Parent do
local s = 5.5 + 1.2 * math.sin(os.clock() * 4)
disc.Size = Vector3.new(0.1, s, s)
RunService.Heartbeat:Wait()
end
end)
local bb = new("BillboardGui", { Name = "TutorialSign", Adornee = anchorPart, AlwaysOnTop = true, Size = UDim2.fromOffset(240, 110),
StudsOffsetWorldSpace = Vector3.new(0, 6, 0), LightInfluence = 0, ResetOnSpawn = false, Parent = playerGui }) -- a BillboardGui inside a ScreenGui is not drawn
local f = new("Frame", { BackgroundTransparency = 1, Size = UDim2.fromScale(1, 1), Parent = bb })
new("TextLabel", { BackgroundColor3 = NAVY, BackgroundTransparency = 0.05, Size = UDim2.new(1, 0, 0, 52), Text = title, FontFace = K.FONT, TextSize = 28,
TextColor3 = WHITE, Parent = f }, { new("UICorner", { CornerRadius = UDim.new(0, 16) }), new("UIStroke", { Color = GOLD, Thickness = 3, ApplyStrokeMode = Enum.ApplyStrokeMode.Border }) })
local arrow = new("TextLabel", { BackgroundTransparency = 1, Position = UDim2.fromOffset(0, 50), Size = UDim2.new(1, 0, 0, 56), Text = "▼", FontFace = K.FONT, TextSize = 48,
TextColor3 = GOLD, Parent = f }, { new("UIStroke", { Color = Color3.fromRGB(60, 40, 0), Thickness = 2 }) })
table.insert(targetFx, bb)
task.spawn(function()
while bb.Parent do
arrow.Position = UDim2.fromOffset(0, 50 + 8 * math.sin(os.clock() * 6))
RunService.Heartbeat:Wait()
end
end)
end
---------------------------------------------------------------- walk to a machine part
-- route: (outside the zone) player -> in front of the gate -> just inside the gate -> the spot at the machine
local function walkTo(anchorPart, title, windowName, nearText, farText)
local _, plot = myMachine()
local win = gui:FindFirstChild(windowName)
local stand
do
local inner = plot and (plot.Position - Vector3.new(plot.CFrame.LookVector.X, 0, plot.CFrame.LookVector.Z).Unit * (plot.Size.Z / 2 - 3)) or anchorPart.Position
local towards = Vector3.new(inner.X - anchorPart.Position.X, 0, inner.Z - anchorPart.Position.Z)
stand = anchorPart.Position + (towards.Magnitude > 0.1 and towards.Unit * 4.5 or Vector3.zero)
end
showTarget(anchorPart, stand, title)
local lastBuild, lastPos = 0, nil
freeze(false)
walkMode(farText)
local r = waitUntil(function()
if win and win.Visible then return true end
local root = hrp()
if root then
local pos = root.Position
local flatD = Vector3.new(anchorPart.Position.X - pos.X, 0, anchorPart.Position.Z - pos.Z).Magnitude
bannerText.Text = flatD < 12 and nearText or farText
if (not lastPos or (pos - lastPos).Magnitude > 2.5 or os.clock() - lastBuild > 3) then
lastPos, lastBuild = pos, os.clock()
local pts = { pos }
if plot then
local look = Vector3.new(plot.CFrame.LookVector.X, 0, plot.CFrame.LookVector.Z).Unit
local loc = plot.CFrame:PointToObjectSpace(pos)
local inside = math.abs(loc.X) < plot.Size.X / 2 - 1 and math.abs(loc.Z) < plot.Size.Z / 2 - 1
if not inside then
table.insert(pts, plot.Position - look * (plot.Size.Z / 2 + 3))
table.insert(pts, plot.Position - look * (plot.Size.Z / 2 - 3))
end
end
table.insert(pts, stand)
if (Vector3.new(stand.X, 0, stand.Z) - Vector3.new(pos.X, 0, pos.Z)).Magnitude < 3 then clearMarkers() else buildPath(pts) end
end
end
return false
end)
clearTarget()
return r
end
-- another window opened instead of the right one: ask to close it
local WINDOWS = { "CraftMenu", "RecycleMenu", "WorkshopMenu", "TradeMenu", "MarketMenu", "ShopMenu", "PremiumMenu", "InventoryMenu" }
local function openWindowOtherThan(name)
for _, n in WINDOWS do
local w = gui:FindFirstChild(n)
if n ~= name and w and w.Visible then return w end
end
return nil
end
local function closeButtonOf(w)
local p = w:FindFirstChild("Panel")
return p and (p:FindFirstChild("Close") or p:FindFirstChild("ArtClose"))
end
---------------------------------------------------------------- the steps
local function inventory() return player:FindFirstChild("OrnamentInventory") end
local function countSlots()
local s = player:GetAttribute("CraftSlots")
if typeof(s) ~= "string" then return 0 end
local _, n = s:gsub("1", "")
return n
end
local function find(root, name)
return root and root:FindFirstChild(name, true)
end
local function panelWithLabel(root, text)
if not root then return nil end
for _, d in root:GetDescendants() do
if d:IsA("TextLabel") and d.Text == text then return d.Parent end
end
return nil
end
local function welcome()
setStep(0)
local r = say(nil, "<font size=\"32\" color=\"#FFCD46\"><b>Hi there! 🎄</b></font>\nHere you make Christmas ornaments from magic shards, collect rare ones and decorate your plot.\n\nLet me show you how it all works — it only takes a couple of minutes.",
{ buttons = { { id = "go", text = "Let's go!" }, { id = "skip", text = "Skip", kind = "alt" } } })
if r == "skip" then skipped = true; check() end
end
local function hudIntro()
setStep(1)
local shardRow = function() return find(gui:FindFirstChild("Hud"), "ShardRow") end
say(shardRow, "These are your <font color=\"#9FE0FF\"><b>shards 💎</b></font> — the main currency of the game.\nThe generator turns them into ornaments, and you spend them in the shop.\n\nWhile you're low on shards, they build up on their own — the bar under the number shows when the next one arrives.")
say(function() return find(gui:FindFirstChild("Hud"), "LevelRow") end,
"And this is your <font color=\"#FFCD46\"><b>level</b></font>. You get XP from generating, fusing and workout gear.\nNew levels unlock new ornaments, the market and trading.")
end
local function generatorPhase()
local machine = myMachine()
if not machine then return end
local genPart = machine:FindFirstChild("Gen_Button") or machine:FindFirstChild("Glass_Chamber")
local craft = gui:FindFirstChild("CraftMenu")
if not genPart or not craft then return end
local function lost() return not craft.Visible end
while true do
check()
setStep(2)
-- 1) walk
local other = openWindowOtherThan("CraftMenu")
if other then
freeze(true)
say(function() return closeButtonOf(other) end, "Right now we need the generator — close this window.", { cond = function() return not other.Visible end })
end
walkTo(genPart, "GENERATOR", "CraftMenu",
"You're at the generator! Now " .. OPEN_HINT .. "\n(or just click the generator itself)",
"Go to your <font color=\"#FFCD46\"><b>generator</b></font> — follow the glowing arrows on the ground")
if not craft.Visible then continue end
-- 2) the window
freeze(true)
setStep(3)
local page = craft.Panel:FindFirstChild("PageCreate")
local res = "ok"
if page and not page.Visible then
res = say(function() return craft.Panel:FindFirstChild("TabCreate") end, "Open the “Create” tab.", { cond = function() return page.Visible end, lost = lost })
end
local grid = function() local s = find(page, "ShardSlot1"); return s and s.Parent end
if res == "ok" then
res = say(grid, "This is the <b>pattern grid</b>. Each cell is one shard.\nTo make an ornament, put in at least <font color=\"#FFCD46\"><b>" .. Config.MIN_SHARDS .. "</b></font> shards. More shards mean more luck!", { lost = lost })
end
if res == "next" then
res = say(function() return panelWithLabel(page, "Possible drops") end,
"Here you can see <b>which ornaments can drop</b> and their odds.\nIf the pattern looks like an ornament, the odds for that one go up.", { lost = lost })
end
if res == "next" then
res = say(function() local b = find(page, "BoosterSlot"); return b and b.Parent end,
"<b>Boosters</b> multiply the luck of one generation. They're crafted in the Workshop — you can skip them for now.", { lost = lost })
end
if res == "next" then
if countSlots() >= Config.MIN_SHARDS then
res = "ok"
else
setStep(4)
res = say(function() return find(page, "Autofill") end,
"The easiest way — press <font color=\"#9FE0FF\"><b>“Auto Pattern”</b></font>: the generator lays out the best pattern for you.",
{ cond = function() return countSlots() >= Config.MIN_SHARDS end, lost = lost })
end
end
if res == "ok" then
setStep(4)
local before = {}
local inv = inventory()
for _, c in inv and inv:GetChildren() or {} do before[c.Name] = true end
local newToy
local function scan()
for _, c in inv and inv:GetChildren() or {} do if not before[c.Name] then newToy = c end end
return newToy
end
res = say(function() return find(page, "GenerateButton") end,
"Great, the pattern is ready! Now press <font color=\"#FFCD46\"><b>“Create”</b></font> ✨",
{ cond = function() return scan() ~= nil or (not craft.Visible and machine:GetAttribute("GeneratorBusy") == true) end,
lost = function() return not craft.Visible and not machine:GetAttribute("GeneratorBusy") end })
if res == "lost" then
-- the window may close a moment before the busy flag arrives
res = waitUntil(function() return machine:GetAttribute("GeneratorBusy") == true or scan() ~= nil end, nil, 1.5)
end
if res == "ok" then
freeze(false)
walkMode("Look — the generator is making an ornament! ✨")
waitUntil(function() return scan() ~= nil end, nil, 25)
if newToy then
task.wait(1.2) -- let the big "new toy" notification show
freeze(true)
local toy = Config.ToyById[newToy:GetAttribute("Toy")]
local rar = Config.RarityById[newToy:GetAttribute("Rarity")]
local col = rar and rar.Color or WHITE
local hex = string.format("#%02X%02X%02X", col.R * 255, col.G * 255, col.B * 255)
setStep(5)
say(nil, "<font size=\"32\" color=\"#FFCD46\"><b>Hooray, your first ornament! 🎉</b></font>\n<b>" .. (toy and toy.Name or "Ornament") .. "</b> · <font color=\"" .. hex .. "\"><b>" ..
(rar and rar.Name or "") .. "</b></font>\n\nAll ornaments are kept in your <b>Inventory</b> — you can hang them on your tree, sell them on the market or trade them.\nExtras turn back into shards in the <b>shredder</b>. Come on, I'll show you!",
{ next = "Let's go" })
return newToy
end
end
end
-- the window was closed in the middle: back to the walk
freeze(false)
end
end
local function shredderPhase(toyItem)
local machine = myMachine()
if not machine then return end
local recPart = machine:FindFirstChild("Rec_Button")
local shred = gui:FindFirstChild("RecycleMenu")
if not recPart or not shred then return end
local function lost() return not shred.Visible end
while true do
check()
setStep(6)
local other = openWindowOtherThan("RecycleMenu")
if other then
freeze(true)
say(function() return closeButtonOf(other) end, "Now we need the shredder — close this window.", { cond = function() return not other.Visible end })
end
walkTo(recPart, "SHREDDER", "RecycleMenu",
"You're at the shredder! Now " .. OPEN_HINT .. "\n(or click the shredder itself)",
"Now go to the <font color=\"#7CF0A0\"><b>shredder</b></font> — it's the other half of the machine")
if not shred.Visible then continue end
freeze(true)
setStep(7)
local page = shred.Panel:FindFirstChild("PageRecycle")
local res = "ok"
if page and not page.Visible then
res = say(function() return shred.Panel:FindFirstChild("TabRecycle") end, "Open the “Recycle” tab.", { cond = function() return page.Visible end, lost = lost })
end
local recBtn = find(page, "RecycleButton")
local function tile()
local list = find(page, "SelectAll")
local sf = list and list.Parent:FindFirstChildWhichIsA("ScrollingFrame", true)
if not sf then return nil end
local best
for _, c in sf:GetChildren() do
if c:IsA("TextButton") and c.Visible and (not best or c.LayoutOrder < best.LayoutOrder) then best = c end
end
return best
end
if res == "ok" then
res = say(function() local b = find(page, "SelectAll"); return b and b.Parent end,
"Here are all your ornaments. The shredder turns them back into <font color=\"#9FE0FF\"><b>shards</b></font>.\nRare ornaments give more shards.", { lost = lost })
end
if res == "next" then
res = say(tile, "Click an ornament to <b>select</b> it.", { cond = function() return recBtn and recBtn.Active end, lost = lost })
end
if res == "ok" then
res = say(function() return recBtn and recBtn.Parent end,
"On the right you can see how many shards you'll get.\n\nPress <font color=\"#FFCD46\"><b>“Recycle”</b></font>!", { cond = function() return not shred.Visible end })
-- (pressing it closes the window)
local startShards = player:GetAttribute("Shards") or 0
freeze(false)
walkMode("The shredder is recycling the ornament… ♻️")
local got = waitUntil(function() return (player:GetAttribute("Shards") or 0) > startShards or machine:GetAttribute("ShredderBusy") == true end, nil, 2.5)
if got == "ok" then
waitUntil(function() return (player:GetAttribute("Shards") or 0) > startShards end, nil, 15)
local gained = (player:GetAttribute("Shards") or 0) - startShards
task.wait(0.8)
freeze(true)
setStep(8)
say(function() return find(gui:FindFirstChild("Hud"), "ShardRow") end,
(gained > 0 and ("<font color=\"#9FE0FF\"><b>+" .. gained .. " shards</b></font> are back in your balance! 💎\n") or "") ..
"That's the game loop: make ornaments, keep the best ones and recycle the extras into shards for new tries.")
return
end
end
freeze(false)
end
end
local function shopPhase()
local shopWin = gui:FindFirstChild("ShopMenu")
if not shopWin then return end
setStep(9)
freeze(true)
local other = openWindowOtherThan("ShopMenu")
if other then
say(function() return closeButtonOf(other) end, "Close this window.", { cond = function() return not other.Visible end })
end
say(function() return find(gui:FindFirstChild("Hud"), "ShopButton") end,
"One last thing — the <font color=\"#FF8A8A\"><b>Shop</b></font>. Press the shop button.", { cond = function() return shopWin.Visible end })
local function page()
for _, c in shopWin.Panel:GetChildren() do
if c:IsA("CanvasGroup") and c.Name:sub(1, 4) == "Page" and c.Visible then return c end
end
return nil
end
local r = say(page, "Here you spend shards on <b>decorations for your plot</b>: a tree, garlands, workout gear and more.\nPlace what you buy with the “Place” button, and hang ornaments from your inventory on your tree 🎄",
{ lost = function() return not shopWin.Visible end })
if r == "next" and shopWin.Visible then
say(function() return closeButtonOf(shopWin) end, "Close the shop and start playing!", { cond = function() return not shopWin.Visible end })
end
end
local function finish()
S.mode = "card"
say(nil, "<font size=\"32\" color=\"#FFCD46\"><b>Tutorial complete! ⭐</b></font>\nNow you know the basics. Generate ornaments, collect rare ones, upgrade your machine in the <b>Workshop</b> and decorate your tree.\n\nGood luck and Happy New Year! 🎄",
{ next = "Play!" })
end
---------------------------------------------------------------- run
local running = true
skipBtn.Activated:Connect(function()
if not running then return end
skipped = true
end)
local ok, err = pcall(function()
welcome()
hudIntro()
local toy = generatorPhase()
if toy then shredderPhase(toy) end
shopPhase()
finish()
end)
if not ok and err ~= SKIP then warn("[Tutorial] " .. tostring(err)) end
running = false
layoutConn:Disconnect()
markerConn:Disconnect()
freeze(false)
clearTarget()
markerFolder:Destroy()
tg:Destroy()
if tutorialRemote then tutorialRemote:FireServer("Done") end
-- an admin can reset the tutorial again later in this session: wait for TutorialDone true -> false and run a fresh copy
do
local t = os.clock()
while player:GetAttribute("TutorialDone") ~= true and os.clock() - t < 15 do task.wait(0.2) end
while player:GetAttribute("TutorialDone") do player:GetAttributeChangedSignal("TutorialDone"):Wait() end
local copy = script:Clone()
copy.Parent = script.Parent
script:Destroy()
end