So I’m having an issue with this cash collection system I made, as what is mentioned in the title, in single-player, the cash collectible can be collected normally, but in multi-player, neither players can collect the cash
local ColSer = game:GetService("CollectionService")
local Players = game:GetService("Players")
local db = false
local function TheFunc(obj)
obj.Touched:Connect(function(toucher)
if db == true then return end
db = true
local plr = Players:GetPlayerFromCharacter(toucher.Parent)
if plr then
local Bag = Players[plr.Name].Bag
local Cash : IntValue = Bag.Cash
print("Hit")
Cash.Value += 15
obj:Destroy()
wait(0.1)
db = false
end
end)
end
for i, v : Part in next, ColSer:GetTagged("Cash") do
TheFunc(v)
end
ColSer:GetInstanceAddedSignal("Cash"):Connect(function(obj)
for i, v : Part in next, ColSer:GetTagged("Cash") do
TheFunc(v)
end
TheFunc(obj)
end)
Mind you, this is the only script that detects if a player collects a cash object