Hello, if you have read my previous help request on how to create a Shop Field, I thank those who have attempted to help solve my problem. On my own time, I have managed to create a simpler solution which is nearly done, my final problem is debouncing.
local OpenShop = game.ReplicatedStorage.OpenShop
local CloseShop = game.ReplicatedStorage.CloseShop
local debounce = false
script.Parent.Touched:Connect(function(hit)
if not debounce and game.Players:GetPlayerFromCharacter(hit.Parent) then
debounce = true
wait(1)
print("Welcome!")
OpenShop:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
end)
script.Parent.TouchEnded:Connect(function(miss)
if debounce and miss then
debounce = false
wait(1)
print("Goodbye!")
CloseShop:FireClient(game.Players:GetPlayerFromCharacter(miss.Parent))
wait(1)
end
end)
Functionally, this script works in the sense of operating the RemoteEvent and summoning and dismissing the GUI, but due to the nature of using a brick-based field, it often registers a Touch or TouchEnded multiple times at once which can often break the GUI.
My question is that if there’s a debounce method which ensures that the Touch and TouchEnded events only work when the player has completely entered and left the field without any mashed triggers?