Currency System Isn't working

Hello! I made a currency system but it doesnt work, Nothing came in the output so heres the scripts.

leaderstats

game.Players.PlayerAdded:Connect(function(plr)
	local f = Instance.new("Folder", plr)
	f.Name = "leaderstats"
	local noobcoins = Instance.new("IntValue", f)
	noobcoins.Name = "Noob Coins"
	noobcoins.Value = 0
end)

Collect Coin Script (CollectScript)

WaitTime = 60 -- How many seconds to respawn the coin!
Amount = 1 -- Amount of coins per coin!
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:FindFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local Score = stats:findFirstChild("Noob Coins")
				if (Score~=nil) then
					Score.Value = Score.Value + Amount
				end
			end
		end
		script.Parent.Transparency = 1
		script.Disabled = true
		wait(WaitTime)
		script.Parent.Transparency = 0
		script.Disabled = false
	end
end

Explorer >>>>

Screenshot 2021-05-28 092818
Screenshot 2021-05-28 092836

Can you tell us what exactly is not working with the currency system? Is the leaderstats not appearing, or is the coin being picked up not adding to your amount?

1 Like

You have not set the onTouched function to be performed when touching, put this line at the end of the script

script.Parent.Touched:Connect(onTouched)
3 Likes