so i was normally creating a game, with a shop that used a prompt to open (it’s a GUI) and i used a basic debounce system to open & close the shop GUI but when i was messing with it i found a pretty annoying error.
so basically the first time you trigger the prompt, the GUI opens, normal right? well the second time, you have to trigger it 2 times for it to open, and it’s not really a big issue but annoying for me having to hold a prompt 2 times for it to open, and it’s because the debounce, because if i have no debounce and i trigger a prompt with no debounce and no different action, it works normally and doesn’t have to be triggered 2 times.
would be happy if someone could help fixing this, because it also happened in other games i created.
shop open code:
script.Parent.ShopFrame.Position = UDim2.new(0.05, 0, 1.4, 0) -- Setting the main position for the frame.
local player = script.Parent.Parent.Parent -- The player (This is a Script so i just define the player like this)
local Prompt = workspace.Shack.ShopPart.Open
local Merchant = workspace.Shack.Merchant
-- Prompt is the button with the issue, and merchant is just a NPC with animations.
local positions = {
openShop = UDim2.new(0.05, 0, 0.11, 0), -- Open UI animation position.
closeShop = UDim2.new(0.05, 0, 1.4, 0) -- Close UI animation position.
}
local OPEN_TWEEN = game:GetService("TweenService"):Create(script.Parent.ShopFrame, TweenInfo.new(0.3, Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0), {Position = positions.openShop})
local CLOSE_TWEEN = game:GetService("TweenService"):Create(script.Parent.ShopFrame, TweenInfo.new(0.3, Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0), {Position = positions.closeShop})
-- OPEN_TWEEN and CLOSE_TWEEN are the tweens of the GUI.
local function open()
OPEN_TWEEN:Play()
end
local function close()
CLOSE_TWEEN:Play()
end
-- open and close are functions that when called, open the shop GUI.
local function isOpen() -- Checks if the shop GUI is visible.
return script.Parent.ShopFrame.Position == positions.openShop
end
Prompt.Triggered:Connect(function(player) -- MAIN ISSUE HERE
if not isOpen() then -- Works perfectly!
open() -- open function is called.
else -- BUT, here this else statement won't run for some reason if you don't trigger the 2 prompts as i said in the post.
close() -- close function is called.
end
end)
-- [[ BELOW IS ANIMATION TRACKS FOR THE MERCHANT ]]
-- // ANIMATION TRACKS
local info = game:WaitForChild("Info")
local isDay: BoolValue = info:WaitForChild("IsDay")
local isNight: BoolValue = info:WaitForChild("IsNight")
wait()
local Standing = Merchant.Merchant:LoadAnimation(script.StandLoop)
local Sitting = Merchant.Merchant:LoadAnimation(script.SitLoop)
Standing:Play()
isDay:GetPropertyChangedSignal("Value"):Connect(function()
if isDay.Value == true then
Sitting:Stop()
Standing:Play()
end
end)
isNight:GetPropertyChangedSignal("Value"):Connect(function()
if isNight.Value == true then
Standing:Stop()
Sitting:Play()
end
end)
the error is at the line 35 on ‘Prompt.Triggered:Connect(function(player)’, it has a message.
by the way, all the solutions i have tried to fix this error won’t work either.