-- Place: ServerScriptService.Collectibles (Script) local Players = game:GetService("Players") local coins = workspace:WaitForChild("Coins") local collected: {[Player]: {[Instance]: boolean}} = {} local function initialize(player: Player) if collected[player] then return end collected[player] = {} local stats = Instance.new("Folder") stats.Name = "leaderstats" local score = Instance.new("IntValue") score.Name = "Coins" score.Value = 0 score.Parent = stats stats.Parent = player end Players.PlayerAdded:Connect(initialize) for _, player in Players:GetPlayers() do initialize(player) end Players.PlayerRemoving:Connect(function(player) collected[player] = nil end) for _, coin in coins:GetChildren() do if not coin:IsA("BasePart") then continue end coin.Touched:Connect(function(hit) local character = hit:FindFirstAncestorOfClass("Model") if not character then return end local player = Players:GetPlayerFromCharacter(character) local humanoid = character:FindFirstChildOfClass("Humanoid") local root = character:FindFirstChild("HumanoidRootPart") if not player or not humanoid or humanoid.Health <= 0 then return end if not root or not root:IsA("BasePart") then return end if not ((root.Position - coin.Position).Magnitude <= 8) then return end local seen = collected[player] if not seen or seen[coin] then return end local stats = player:FindFirstChild("leaderstats") local score = stats and stats:FindFirstChild("Coins") if not score or not score:IsA("IntValue") then return end -- No yielding between checking and marking this coin. seen[coin] = true score.Value += 1 print(player.Name, "collected", coin.Name, "total", score.Value) end) end