I put the two players in the list table as the first two arguments.
The script works it’s just that it clones the value instances more than 4 times.
local MatchInit = {}
--Server Storage
local Rep = game:GetService('ReplicatedStorage')
local Players = game:GetService('Players')
--Folders
local Values = Rep:WaitForChild('Values')
local Mods = Rep:WaitForChild('Modules')
local Events = Rep:WaitForChild('Events')
local Spawns = workspace:WaitForChild('SpawnLocations')
--Variables
local L = Values:WaitForChild('Loser')
local R = Values:WaitForChild('Round')
local W = Values:WaitForChild('Winner')
local C = Values:WaitForChild('CountDown')
local F = Values:WaitForChild('FirstCount')
local S = Values:WaitForChild('SecondCount')
local Base = Spawns:WaitForChild('BaseSpawn')
local A1Folder = Spawns:WaitForChild('Area1Spawns')
local A2Folder = Spawns:WaitForChild('Area2Spawns')
local MS = Events:WaitForChild('MatchStart')
local ME = Events:WaitForChild('MatchEnd')
local GM = require(Mods:WaitForChild('GameMethods'))
--Code
List = {}
local function detectPlayerValueChanged(plr, plr2, KC1, KC2)
local cloned = KC1:Clone()
local cloned2 = KC2:Clone()
cloned.Parent = plr
cloned2.Parent = plr2
plr.Store.KO.Changed:Connect(function(newVal)
print("Plr1 Value Changed")
cloned.Value += 1
end)
plr2.Store.KO.Changed:Connect(function(newVal)
print("Plr2 Value Changed")
cloned2.Value += 1
end)
end
local function checkPlayers()
if #List == 1 then
print("A player won")
ME:Fire(GM.FinishMethods.Finished)
end
end
local function checkPlayerLeft()
for i, v in ipairs(List) do
Players.PlayerRemoving:connect(function(plr)
if v == plr then
ME:Fire(GM.FinishMethods.PlayerLeft)
print(plr.." ".."Left")
else
end
end)
end
end
local function removeList(player)
for i,v in ipairs(List) do
if v == player then
table.remove(List,i)
checkPlayerLeft()
checkPlayers()
end
end
end
local function moveToLobby(player)
player.RespawnLocation = Base
player:LoadCharacter()
end
local function startSpawn(player)
player.RespawnLocation = Base
end
local function addPlayer(player,spawnFolder)
local debounce = false
player.RespawnLocation = spawnFolder
player:LoadCharacter()
local char = player.Character
detectPlayerValueChanged(List[1],List[2],F,S)
end
function MatchInit.SendPlayers(folder,plrToAdd)
local AS = folder:GetChildren()
table.insert(List, plrToAdd)
if table.find(List,List[1],2) then
table.remove(List,2)
else
end
repeat
wait()
until #List == GM.Minimum
print(#List)
wait(GM.TransitionTime)
local spawn1 = AS[1]
local spawn2 = AS[2]
for i, v in ipairs(List) do
if v == List[1] then
addPlayer(v, spawn1)
else
end
if v == List[2] then
addPlayer(v, spawn2)
else
end
end
end
Players.PlayerAdded:Connect(startSpawn)
return MatchInit
I looked in the players already and the values are different. KC1 is given to the first player in the list and the value I assigned to it is called “FirstCount” and KC2 is given to the second player as the value called “SecondCount”.