From 4c648d139e12f42daa64d34cc565565d7b835882 Mon Sep 17 00:00:00 2001 From: min Date: Tue, 9 Jun 2026 13:39:55 +0300 Subject: [PATCH] =?UTF-8?q?fix(g4):=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D0=BA=D0=B0=D1=81=D0=B0=D0=BD=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20E-=D0=BD=D0=B0=D0=B6?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Проблема: 1. Heartbeat-зов __rbxl_player_x() возвращал константу после первого касания кнопки (возможно lua-coroutine / state-issue в Heartbeat). 2. Дверь не открывалась — InputBegan E видимо не доходит или фильтр inRange всегда true. Решение: упростил — кнопка реагирует на Touched (как кнопка-педаль), без E и без проверки расстояния. Это и понятнее для урока. Текст подсказки изменён на 'Наступи на красную кнопку'. Дверь поднимается через TweenService при касании кнопки. --- src/community/docsGamesBuildersLua.js | 72 +++++++-------------------- 1 file changed, 19 insertions(+), 53 deletions(-) diff --git a/src/community/docsGamesBuildersLua.js b/src/community/docsGamesBuildersLua.js index e3afb6f..5cf12e5 100644 --- a/src/community/docsGamesBuildersLua.js +++ b/src/community/docsGamesBuildersLua.js @@ -278,7 +278,7 @@ end)`; g4_main: `-- === ИГРА «КНОПКА-ОТКРЫВАШКА» — главный скрипт (Lua) === ${SNIPPET_BROADCAST} -__rbxl_show_text("Подойди к красной кнопке и нажми E", 4) +__rbxl_show_text("Наступи на красную кнопку чтобы открыть дверь", 4) local winSound = Instance.new("Sound", workspace) winSound.SoundId = "win"; winSound.Volume = 1 @@ -293,69 +293,35 @@ winEvent.Event:Connect(function() __rbxl_spawn_particles("confetti", px, py + 3, pz, 3, 3) end)`, g4_button: `-- === Скрипт кнопки (Lua) === --- Висит на красной кнопке. Реагирует на E когда игрок рядом. -local UserInputService = game:GetService("UserInputService") +-- Висит на красной кнопке. Срабатывает по касанию игрока (как кнопка-педаль). local Players = game:GetService("Players") -local RunService = game:GetService("RunService") local TweenService = game:GetService("TweenService") local part = script.Parent -local player = Players.LocalPlayer local opened = false -local inRange = false -local hintGui = nil --- Подсказка над кнопкой при подходе -local function showHint() - if hintGui then return end - hintGui = Instance.new("BillboardGui", part) - hintGui.Size = UDim2.new(4, 0, 1, 0) - hintGui.StudsOffset = Vector3.new(0, 2, 0) - hintGui.AlwaysOnTop = true - local label = Instance.new("TextLabel", hintGui) - label.Size = UDim2.new(1, 0, 1, 0) - label.BackgroundTransparency = 1 - label.TextColor3 = Color3.fromRGB(255, 255, 255) - label.TextStrokeTransparency = 0 - label.TextScaled = true - label.Text = "[E] Открыть дверь" -end -local function hideHint() - if hintGui then hintGui:Destroy(); hintGui = nil end -end - --- Каждый кадр проверяем расстояние до игрока -local _debugTick = 0 -RunService.Heartbeat:Connect(function(dt) - if opened then return end - local px = __rbxl_player_x() - local pz = __rbxl_player_z() - local dx = part.Position.X - px - local dz = part.Position.Z - pz - local dist = math.sqrt(dx*dx + dz*dz) - _debugTick = _debugTick + (dt or 0.016) - if _debugTick > 1 then - _debugTick = 0 - print("[g4] px=", px, "pz=", pz, "dist=", dist, "inRange=", inRange) - end - if dist <= 4 and not inRange then - inRange = true - showHint() - elseif dist > 4 and inRange then - inRange = false - hideHint() - end -end) +-- Подсказка над кнопкой +local hintGui = Instance.new("BillboardGui", part) +hintGui.Size = UDim2.new(4, 0, 1, 0) +hintGui.StudsOffset = Vector3.new(0, 2, 0) +hintGui.AlwaysOnTop = true +local label = Instance.new("TextLabel", hintGui) +label.Size = UDim2.new(1, 0, 1, 0) +label.BackgroundTransparency = 1 +label.TextColor3 = Color3.fromRGB(255, 255, 255) +label.TextStrokeTransparency = 0 +label.TextScaled = true +label.Text = "Наступи на кнопку" local clickSound = Instance.new("Sound", part) clickSound.SoundId = "click"; clickSound.Volume = 0.8 -UserInputService.InputBegan:Connect(function(input, gp) - if gp then return end - if opened or not inRange then return end - if input.KeyCode ~= Enum.KeyCode.E then return end +part.Touched:Connect(function(hit) + if opened then return end + local h = hit.Parent and hit.Parent:FindFirstChild("Humanoid") + if not h then return end opened = true - hideHint() + hintGui:Destroy() clickSound:Play() __rbxl_show_text("Дверь открывается!", 2) part.Color = Color3.fromRGB(100, 255, 100) -- зелёная