fix(g4): кнопка по касанию вместо E-нажатия
Проблема: 1. Heartbeat-зов __rbxl_player_x() возвращал константу после первого касания кнопки (возможно lua-coroutine / state-issue в Heartbeat). 2. Дверь не открывалась — InputBegan E видимо не доходит или фильтр inRange всегда true. Решение: упростил — кнопка реагирует на Touched (как кнопка-педаль), без E и без проверки расстояния. Это и понятнее для урока. Текст подсказки изменён на 'Наступи на красную кнопку'. Дверь поднимается через TweenService при касании кнопки.
This commit is contained in:
parent
39673452cb
commit
4c648d139e
@ -278,7 +278,7 @@ end)`;
|
|||||||
g4_main: `-- === ИГРА «КНОПКА-ОТКРЫВАШКА» — главный скрипт (Lua) ===
|
g4_main: `-- === ИГРА «КНОПКА-ОТКРЫВАШКА» — главный скрипт (Lua) ===
|
||||||
${SNIPPET_BROADCAST}
|
${SNIPPET_BROADCAST}
|
||||||
|
|
||||||
__rbxl_show_text("Подойди к красной кнопке и нажми E", 4)
|
__rbxl_show_text("Наступи на красную кнопку чтобы открыть дверь", 4)
|
||||||
|
|
||||||
local winSound = Instance.new("Sound", workspace)
|
local winSound = Instance.new("Sound", workspace)
|
||||||
winSound.SoundId = "win"; winSound.Volume = 1
|
winSound.SoundId = "win"; winSound.Volume = 1
|
||||||
@ -293,22 +293,15 @@ winEvent.Event:Connect(function()
|
|||||||
__rbxl_spawn_particles("confetti", px, py + 3, pz, 3, 3)
|
__rbxl_spawn_particles("confetti", px, py + 3, pz, 3, 3)
|
||||||
end)`,
|
end)`,
|
||||||
g4_button: `-- === Скрипт кнопки (Lua) ===
|
g4_button: `-- === Скрипт кнопки (Lua) ===
|
||||||
-- Висит на красной кнопке. Реагирует на E когда игрок рядом.
|
-- Висит на красной кнопке. Срабатывает по касанию игрока (как кнопка-педаль).
|
||||||
local UserInputService = game:GetService("UserInputService")
|
|
||||||
local Players = game:GetService("Players")
|
local Players = game:GetService("Players")
|
||||||
local RunService = game:GetService("RunService")
|
|
||||||
local TweenService = game:GetService("TweenService")
|
local TweenService = game:GetService("TweenService")
|
||||||
|
|
||||||
local part = script.Parent
|
local part = script.Parent
|
||||||
local player = Players.LocalPlayer
|
|
||||||
local opened = false
|
local opened = false
|
||||||
local inRange = false
|
|
||||||
local hintGui = nil
|
|
||||||
|
|
||||||
-- Подсказка над кнопкой при подходе
|
-- Подсказка над кнопкой
|
||||||
local function showHint()
|
local hintGui = Instance.new("BillboardGui", part)
|
||||||
if hintGui then return end
|
|
||||||
hintGui = Instance.new("BillboardGui", part)
|
|
||||||
hintGui.Size = UDim2.new(4, 0, 1, 0)
|
hintGui.Size = UDim2.new(4, 0, 1, 0)
|
||||||
hintGui.StudsOffset = Vector3.new(0, 2, 0)
|
hintGui.StudsOffset = Vector3.new(0, 2, 0)
|
||||||
hintGui.AlwaysOnTop = true
|
hintGui.AlwaysOnTop = true
|
||||||
@ -318,44 +311,17 @@ local function showHint()
|
|||||||
label.TextColor3 = Color3.fromRGB(255, 255, 255)
|
label.TextColor3 = Color3.fromRGB(255, 255, 255)
|
||||||
label.TextStrokeTransparency = 0
|
label.TextStrokeTransparency = 0
|
||||||
label.TextScaled = true
|
label.TextScaled = true
|
||||||
label.Text = "[E] Открыть дверь"
|
label.Text = "Наступи на кнопку"
|
||||||
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 clickSound = Instance.new("Sound", part)
|
local clickSound = Instance.new("Sound", part)
|
||||||
clickSound.SoundId = "click"; clickSound.Volume = 0.8
|
clickSound.SoundId = "click"; clickSound.Volume = 0.8
|
||||||
|
|
||||||
UserInputService.InputBegan:Connect(function(input, gp)
|
part.Touched:Connect(function(hit)
|
||||||
if gp then return end
|
if opened then return end
|
||||||
if opened or not inRange then return end
|
local h = hit.Parent and hit.Parent:FindFirstChild("Humanoid")
|
||||||
if input.KeyCode ~= Enum.KeyCode.E then return end
|
if not h then return end
|
||||||
opened = true
|
opened = true
|
||||||
hideHint()
|
hintGui:Destroy()
|
||||||
clickSound:Play()
|
clickSound:Play()
|
||||||
__rbxl_show_text("Дверь открывается!", 2)
|
__rbxl_show_text("Дверь открывается!", 2)
|
||||||
part.Color = Color3.fromRGB(100, 255, 100) -- зелёная
|
part.Color = Color3.fromRGB(100, 255, 100) -- зелёная
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user