Hello, I have a gamepass door in my game and I included a debounce in my script. However the debounce does not seem to be working properly
The script
local mps = game:GetService("MarketplaceService")
local debounce = false
script.Parent.Touched:Connect(function(hit)
if debounce == false then
print("debounce is false")
debounce = true
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
print(player)
if mps:UserOwnsGamePassAsync(player.UserId,11828899) then
script.Parent.CanCollide = false
print("Player owns gamepass")
wait(2)
script.Parent.CanCollide = true
debounce = false
else
print("Player does not own gamepass")
mps:PromptGamePassPurchase(player.UserId,11828899)
wait(10)
debounce = false
end
end
elseif debounce == true then
print("Debounce is true") --Included this after problems started arising
wait(10)
else
print("Debounce has error") --Included this after problems started arising
end
end)
The debounce actually worked at first but today it does not seem like it is working.
The output:
Debounce is false --Ignore this as this as the script decided to print this out when I am joining. So as the first true debounce print
Debounce is true (x1079)
17:50:49.216 - Disconnect from ::ffff:127.0.0.1|51173
And for some reason, it always prints the debounce check when I am joining and nobody else is touching it。
So what is wrong with the script?