What’s the problem?
Hi there! I made a coins system that sets every coin when you collect it in a table with the players userid and the coins position. It looks like this:
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Variables
local remoteEvents = ReplicatedStorage.RemoteEvents
local coinsTable = {}
-- Core Script
for _, coinsZone in pairs(game.Workspace.CoinsAreas:GetChildren()) do
for _, coin in pairs(coinsZone:GetChildren()) do
coin.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not table.find(coinsTable , coin.Position, player.UserId) then
print("Coin has been touched by "..player.Name)
table.insert(coinsTable, player.UserId, coin.Position)
remoteEvents.CoinsTouched:FireClient(player, coin)
end
end
end)
end
end
It works perfectly fine with 1 coin, but if I insert 2 or more coins, this happens when I collect the first coin you can’t collect it, but if you collect the second coin you can pick up the first coin again, without that I removed the coin from the table.
(Sorry if I do something wrong at adding things to tables, I didn’t used tables much before.)
Please let me know if you know how to fix this, or just have a whole better way of inserting a coin with a player in a table. Thanks for reading!