What is the best way to make a money-collecting system?
-
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).
-
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).
-
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)