I’d like to make it so that a GUI pops up once when a player touches a part and has a 10 second cooldown before they can touch that part again, but whenever the player touches the part it pops up 30+ GUIs a second and has no cooldown. I’ve tried adding a wait(10) or a debounce but neither of those really worked.
Code:
local Players = game:GetService("Players")
local function onTouched(hit)
local character = hit.Parent
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid then
print("Player touched AreaTransitionMainGym!")
local new = game.ReplicatedStorage.MainGymPopup:Clone()
new.Parent = script.Parent.PopupGuiGym
end
end
local areaTransitionMainGym = game.Workspace:WaitForChild("AreaTransitionMainGym")
areaTransitionMainGym.Touched:Connect(onTouched)
local Players = game:GetService("Players")
local Cooldown = false
local function onTouched(hit)
local character = hit.Parent
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid and not Cooldown then
local new = game.ReplicatedStorage.MainGymPopup:Clone()
new.Parent = script.Parent.PopupGuiGym
Cooldown = true
wait(10)
Cooldown = false
end
end
local areaTransitionMainGym = game.Workspace:WaitForChild("AreaTransitionMainGym")
areaTransitionMainGym.Touched:Connect(onTouched)