Money collecting system?

What is the best way to make a money-collecting system?

  1. Server loops through coins when they are added or removed, and when a player touches one it gives money directly. (I did this and the Debounce is enabled for all coins for some reason, so when one player touches a coin every coin receives the debounce and others have to wait for the debounce as well).

  2. A local script inside StarterPlayerScripts that fires an event to the server when coin touched, (which then checks if the player is in range from the coin then gives the player the coin value and the server removes the coin object).

  3. Your opinion on how to do a system like this?

--// This is from the "1st" example.

Collected = false
Earth.ChildAdded:Connect(function()
	for _,Loot in ipairs(Earth:GetChildren()) do
		Loot.Main.Touched:Connect(function(hit)
			if not Collected then
				local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
				local LootObject = Loot.Name
				local Amount = CollectValues.Earth[LootObject]
				LootService:Collect(Loot, Player, Amount)
				Collected = true
				wait(1)
				Collected = false
			end
		end)
	end
end)
  1. This is fine, the reason you are experiencing issues with debounce is likely due to there being only one debounce variable. You need a debounce for each player that allows them to pick up coins; avoid using a debounce for the coins themselves. You can do this by using some boolvalues in serverstorage.

  2. Don’t do this, it’s easy to exploit by calling this remote whenever you want. Even if you have a debounce, it is pretty unfair for other players. Stick to method 1.

  3. Your first approach is fine (and is how I would do it). Just change how you use debounce (for players, not coins) and it should work fine.

Good luck with your project, hope this helps.

1 Like