I've been trying to find out the problem but I couldn't quite think of a solution to this problem. This is my code:
local CollectionService = game:GetService("CollectionService")
local CoinsTag = CollectionService:GetTagged("Coins")
local debounce = true
for _, taggedCoin in pairs (CoinsTag) do
taggedCoin.CanCollide = false
taggedCoin.Touched:Connect(function(otherPart)
if otherPart.Parent.Humanoid then
if debounce == true then
debounce = false
local playerName = otherPart.Parent.Name
local player = game.Players:FindFirstChild(playerName)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 20
taggedCoin.Transparency = 1
wait(15) -- Cooldown time
taggedCoin.Transparency = 0
debounce = true
end
end
end)
end
My question is, how do I make other coins work when I gave a cooldown time to one coin using collection service?

1 comment
task.Spawn() i think