Есть ли причина, по которой это столкновение не работает для Roblox Lua? - PullRequest
0 голосов
/ 12 марта 2020

Недавно я добавил этот код в свою игру Roblox.

local detector = script.Parent -- Store a reference to the detector.

function onTouch(part) -- The function that runs when the part is touched.
    print('Shop Opened')
    game.StarterGui.ScreenGui.Shop_Background.Visible = true
    game.StarterGui.ScreenGui.Shop.Visible = true

end 

detector.Touched:connect(onTouch) -- The line that connects the function to the event.

В настоящее время, когда я загружаюсь в игру, она печатает shop opened обычно около 17 раз. GUI открывается и блокирует экран. Когда я наступаю на детектор, он также печатает «магазин открыт». Если я go войду в проводник и сделаю видимым равным false, флажок снимается, но gui все еще остается там. Есть ли способ, как я могу это исправить?

1 Ответ

0 голосов
/ 12 марта 2020
local detector = script.Parent -- Store a reference to the detector.
local debounce = false
function onTouch(part) -- The function that runs when the part is touched.
    if not debounce then
    debounce = true
    print('Shop Opened')
    game.StarterGui.ScreenGui.Shop_Background.Visible = true
    game.StarterGui.ScreenGui.Shop.Visible = true

    end
    wait(2) -- Interval until the next execution of if statement
    debounce = false
end 

detector.Touched:connect(onTouch)

Вы должны добавить debounce, чтобы ограничить запуск функции слишком много раз.

...