Coin collect system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So I added fixed coins on the map (not random spawned) that players can collect. The problem with that is, that it works fine, as long as I use only one coin. As soon as I add another coin, with the same path name, the script seems not to work anymore. Also I have a problem with adding a cooldown, so people can’t just farm as much coins as they want. I tried it with wait(), but it looks like it doesn’t change anything.

  2. What is the issue? Include screenshots / videos if possible!
    Here is my code:

local coinAward = 75

game.Workspace.Test.Test.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local characterName = part.Parent.Name
			local currencyStore = DataStore2("currency", players[characterName])
			currencyStore:Increment(coinAward)
		end
	end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    So I already know that it doesn’t work as soon as I got two models with the same name. But I think putting the same code with a different part wouldn’t be good depending on resources used and I’m pretty sure there is a better solution.

Maybe someone can help me with that problem. Thank you already.

The script doesn’t function as you’d like because, as you said, there is multiple coins with the same path, what you want to do instead is to create the function right after you spawn the coin.

local Coin = Coin:Clone()
--Then move the coin and change properties however you like

local coinAward = 75

Coin.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local characterName = part.Parent.Name
		local currencyStore = DataStore2("currency", players[characterName])
		currencyStore:Increment(coinAward)
	end
end)

Hope this helps!

1 Like

I’d create a Folder containing each coin.
In a Local Script loop through it and detect if it’s touched via a Player.

Then of course give the reward. (and maybe delete the coin?)

1 Like