Hello,
I’m trying to make a capture point system, and have got to the point where I can track the players that are inside the capture points “zone” by adding the player to a table when they enter. Though the the table works currently looks like this:
{
["Team 1"] = {
["Player name"] = UserId,
}
["Team 2"] = {
["Player name"] = UserId,
}
}
But what I would like to do is have it look like:
{
["Team 1"] = 1, -- Value depends on how many players from the team are in the zone
["Team 2"] = 0,
}
But I’m unsure of how I could do it. Here is my current code:
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
function PlayerTracker()
local PlayerTracker = {}
for _, Part in pairs(CollectionService:GetTagged("Hardpoint")) do task.wait()
local TouchingParts = workspace:GetPartsInPart(Part)
for I, TouchingPart in pairs(TouchingParts) do task.wait()
local Player
local Humanoid = TouchingPart.Parent:FindFirstChild("Humanoid")
if Humanoid then
local Player = Players:GetPlayerFromCharacter(TouchingPart.Parent)
if Player then
local PlayerJoinedTable = PlayerTracker[Player.Team.Name] or {};
PlayerTracker[Player.Team.Name] = PlayerJoinedTable
PlayerJoinedTable[Player.Name] = Player.UserId
end
end
end
end
return PlayerTracker
end
local TrackPlayerHandle = RunService.Heartbeat:Connect(function()
print(PlayerTracker())
end)
If anyone could point me in the right direction I would greatly appreciate it!
Thanks