Nothing happens when I touch the coin

Hello, I need help when I touch the coin nothing happens is there something wrong with the script?
im not that good in for loops but can someone tell me what i did wrong?

local coin = game:GetService("CollectionService")
local storage = game:GetService("ReplicatedStorage")
debounce = false

for i, Coins in pairs(coin:GetTagged("Coins")) do
	
	Coins.Touched:Connect(function(hit)
		local humanoid = hit.Parent:FindFirstChild("Humanoid")

		if debounce == false then
			if humanoid then
				debounce = true
				local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
				player.leaderstats.Coins.Value += 1

				storage.CoinRemoteEvent:FireClient(player)

				wait(120)

				debounce = false
			end
		end
	end)

any help is appreciated!

1 Like

This code looks fine mechanically

There’s a few things we’ll need to consider:
Are the Coins already in the Workspace by the time this script runs
Are the Coin Instances properly tagged ‘Coins’ by the time this script runs
And have you used print-debugging during the Touched event to ensure the expected response, such as one under the if humanoid then and just under local humanoid

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.