diff --git a/src/community/docsGamesBuildersLua.js b/src/community/docsGamesBuildersLua.js index 5cf12e5..8025c28 100644 --- a/src/community/docsGamesBuildersLua.js +++ b/src/community/docsGamesBuildersLua.js @@ -278,7 +278,7 @@ end)`; g4_main: `-- === ИГРА «КНОПКА-ОТКРЫВАШКА» — главный скрипт (Lua) === ${SNIPPET_BROADCAST} -__rbxl_show_text("Наступи на красную кнопку чтобы открыть дверь", 4) +__rbxl_show_text("Подойди к красной кнопке и нажми E", 4) local winSound = Instance.new("Sound", workspace) winSound.SoundId = "win"; winSound.Volume = 1 @@ -293,14 +293,14 @@ winEvent.Event:Connect(function() __rbxl_spawn_particles("confetti", px, py + 3, pz, 3, 3) end)`, g4_button: `-- === Скрипт кнопки (Lua) === --- Висит на красной кнопке. Срабатывает по касанию игрока (как кнопка-педаль). -local Players = game:GetService("Players") +-- Висит на красной кнопке. Реагирует на E когда игрок рядом. +local UserInputService = game:GetService("UserInputService") local TweenService = game:GetService("TweenService") local part = script.Parent local opened = false --- Подсказка над кнопкой +-- Подсказка [E] всегда висит над кнопкой пока не открыта local hintGui = Instance.new("BillboardGui", part) hintGui.Size = UDim2.new(4, 0, 1, 0) hintGui.StudsOffset = Vector3.new(0, 2, 0) @@ -311,15 +311,25 @@ label.BackgroundTransparency = 1 label.TextColor3 = Color3.fromRGB(255, 255, 255) label.TextStrokeTransparency = 0 label.TextScaled = true -label.Text = "Наступи на кнопку" +label.Text = "[E] Открыть дверь" local clickSound = Instance.new("Sound", part) clickSound.SoundId = "click"; clickSound.Volume = 0.8 -part.Touched:Connect(function(hit) +UserInputService.InputBegan:Connect(function(input, gp) + if gp then return end if opened then return end - local h = hit.Parent and hit.Parent:FindFirstChild("Humanoid") - if not h then return end + if input.KeyCode ~= Enum.KeyCode.E 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) + if dist > 4 then return end -- слишком далеко + opened = true hintGui:Destroy() clickSound:Play()