Here is a video displaying my issue:
Logic is handled by ModuleScript and it’s required by two different Server-Side scripts which i will provide later in the article.
In this video 1 vs 1 doesn’t work and when player stands on first and second part it applies to 2 vs 2 and 2 vs 2 parts work without any issues. sometimes it has the same issue but other way around, when player steps on 1 vs 1 parts it works without issues but when player steps on 2 vs 2 parts it changes values of 1 vs 1, in this case second and fourth touching parts (of 2 vs 2) don’t do anything, not even change value to 1 vs 1.
I’ve been stuck on this for 2 days and i have modified code bunch of times but i can’t fix the issue, i added few print statements and you can see outputs in the video. I’m new to ModuleScripts so i thought y’all would help me fix the issues. BTW parts are located/placed correctly and Zone module works perfectly fine.
Here is the ModuleScript (i know it’s bunch of lines but it’s mainly copy-pasting the same code):
--// Initials
players = game:GetService("Players")
lobby = workspace.Lobby["Duel Matchmaking"]
ZoneModule = require(game:GetService("ServerStorage")["Server Modules"].Zone)
ServerStorage = game:GetService("ServerStorage")
--// Data
local DuelModule = {
lobby = lobby,
--// Adjustable locations
ToHouse1 = workspace.Houses["Place 1"].House["Teleport Part 1"],
ToHouse2 = workspace.Houses["Place 1"].House["Teleport Part 2"],
Area_1 = nil,
Area_2 = nil,
Area_3 = nil,
Area_4 = nil,
LeftTextLabel = nil,
RightTextLabel = nil,
Countdown = nil,
--// Adjustable values
Countdown_Value = nil,
Player_Value = nil,
--// Creates new zone for player enter and leave part detection
zone1 = ZoneModule.new(ServerStorage.TestPart1),
zone2 = ZoneModule.new(ServerStorage.TestPart2),
zone3 = ZoneModule.new(ServerStorage.TestPart3),
zone4 = ZoneModule.new(ServerStorage.TestPart4)
}
--// Player-Storing table
local Table = {}
--// Those 8 functions do logic of teleporting 2 or 4 players whenever player leaves or enters "Area_1", "Area_2", "Area_3" and "Area_4"
function DuelModule.Plr1_Enter()
DuelModule.zone1.playerEntered:Connect(function(player)
print("Entered ".. DuelModule.zone1.zoneParts[1].Name)
print(("%s enter the ".. DuelModule.Area_1.Name.. ", Parent is ".. DuelModule.Area_1.Parent.Parent.Name):format(player.Name))
if Table[1] ~= nil then
return
end
Table[1] = player.Character
if DuelModule.Player_Value == 2 then
DuelModule.LeftTextLabel.Text = "1/1"
else
if Table[3] ~= nil then
DuelModule.LeftTextLabel.Text = "2/2"
else
DuelModule.LeftTextLabel.Text = "1/2"
end
end
if DuelModule.Player_Value == 2 then
if Table[1] == Table[2] then
return
end
else
if Table[1] == Table[2] or Table[1] == Table[3] or Table[1] == Table[4] then
return
end
end
if DuelModule.Player_Value == 2 then
if Table[2] ~= nil and Table[1] ~= nil then
print(DuelModule.Player_Value.. " Players are standing on TP parts!")
for i = DuelModule.Countdown_Value, 0, -1 do
if Table[2] == nil or Table[1] == nil then
DuelModule.Countdown.Text = ""
return
else
DuelModule.Countdown.Text = string.format("%i", i)
task.wait(1)
end
end
DuelModule.Countdown.Text = ""
Table[1].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[2].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
else
print("Only 1 player standing on TP part!")
end
else
if Table[4] ~= nil and Table[3] ~= nil and Table[2] ~= nil and Table[1] ~= nil then
print(DuelModule.Player_Value.. " Players are standing on TP parts!")
for i = DuelModule.Countdown_Value, 0, -1 do
if Table[4] == nil or Table[3] == nil or Table[2] == nil or Table[1] == nil then
DuelModule.Countdown.Text = ""
return
else
DuelModule.Countdown.Text = string.format("%i", i)
task.wait(1)
end
end
DuelModule.Countdown.Text = ""
Table[1].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[2].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
Table[3].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[4].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
else
print("less than ".. DuelModule.Player_Value.. " player standing on TP part!")
end
end
end)
end
function DuelModule.Plr1_Leave()
DuelModule.zone1.playerExited:Connect(function(player)
print("Exited ".. DuelModule.zone1.zoneParts[1].Name)
print(("%s exited the ".. DuelModule.Area_1.Name.. ", Parent is ".. DuelModule.Area_1.Parent.Parent.Name):format(player.Name))
local PlayerEntered = players:GetPlayerFromCharacter(Table[1])
if Table[1] ~= nil then
if player.UserId == PlayerEntered.UserId then
Table[1] = nil
if DuelModule.Player_Value == 2 then
DuelModule.LeftTextLabel.Text = "0/1"
else
if Table[3] == nil then
DuelModule.LeftTextLabel.Text = "0/2"
else
DuelModule.LeftTextLabel.Text = "1/2"
end
end
else
print("Third party interacted")
end
end
end)
end
function DuelModule.Plr2_Enter()
DuelModule.zone2.playerEntered:Connect(function(player)
print("Entered ".. DuelModule.zone2.zoneParts[1].Name)
print(("%s enter the ".. DuelModule.Area_2.Name.. ", Parent is ".. DuelModule.Area_2.Parent.Parent.Name):format(player.Name))
if Table[2] ~= nil then
return
end
Table[2] = player.Character
if DuelModule.Player_Value == 2 then
DuelModule.RightTextLabel.Text = "1/1"
else
DuelModule.RightTextLabel.Text = "1/2"
end
if DuelModule.Player_Value == 2 then
if Table[1] == Table[2] then
return
end
else
if Table[2] == Table[3] or Table[2] == Table[4] or Table[2] == Table[1] then
return
end
end
if DuelModule.Player_Value == 2 then
if Table[2] ~= nil and Table[1] ~= nil then
print(DuelModule.Player_Value.. " Players are standing on TP parts!")
for i = DuelModule.Countdown_Value, 0, -1 do
if Table[2] == nil or Table[1] == nil then
DuelModule.Countdown.Text = ""
return
else
DuelModule.Countdown.Text = string.format("%i", i)
task.wait(1)
end
end
DuelModule.Countdown.Text = ""
Table[1].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[2].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
else
print("Only 1 player standing on TP part!")
end
else
if Table[4] ~= nil and Table[3] ~= nil and Table[2] ~= nil and Table[1] ~= nil then
print(DuelModule.Player_Value.. " Players are standing on TP parts!")
for i = DuelModule.Countdown_Value, 0, -1 do
if Table[4] == nil or Table[3] == nil or Table[2] == nil or Table[1] == nil then
DuelModule.Countdown.Text = ""
return
else
DuelModule.Countdown.Text = string.format("%i", i)
task.wait(1)
end
end
DuelModule.Countdown.Text = ""
Table[1].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[2].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
Table[3].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[4].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
else
print("less than ".. DuelModule.Player_Value.. " player standing on TP part!")
end
end
end)
end
function DuelModule.Plr2_Leave()
DuelModule.zone2.playerExited:Connect(function(player)
print("Exited ".. DuelModule.zone2.zoneParts[1].Name)
print(("%s exited the ".. DuelModule.Area_2.Name.. ", Parent is ".. DuelModule.Area_2.Parent.Parent.Name):format(player.Name))
local PlayerEntered = players:GetPlayerFromCharacter(Table[2])
if Table[2] ~= nil then
if player.UserId == PlayerEntered.UserId then
Table[2] = nil
if DuelModule.Player_Value == 2 then
DuelModule.RightTextLabel.Text = "0/1"
else
if Table[4] == nil then
DuelModule.RightTextLabel.Text = "0/2"
else
DuelModule.RightTextLabel.Text = "1/2"
end
end
else
print("Third party interacted")
end
end
end)
end
--// Pairs with Plr1
function DuelModule.Plr3_Enter()
DuelModule.zone3.playerEntered:Connect(function(player)
if DuelModule.Player_Value == 2 then
return
end
print("Entered ".. DuelModule.zone3.zoneParts[1].Name)
print(("%s enter the ".. DuelModule.Area_3.Name.. ", Parent is ".. DuelModule.Area_3.Parent.Parent.Name):format(player.Name))
if Table[3] ~= nil then
return
end
Table[3] = player.Character
if Table[1] ~= nil then
DuelModule.LeftTextLabel.Text = "2/2"
else
DuelModule.LeftTextLabel.Text = "1/2"
end
if Table[3] == Table[4] or Table[3] == Table[2] or Table[3] == Table[1] then
return
end
if Table[4] ~= nil and Table[3] ~= nil and Table[2] ~= nil and Table[1] ~= nil then
print(DuelModule.Player_Value.. " Players are standing on TP parts!")
for i = DuelModule.Countdown_Value, 0, -1 do
if Table[4] == nil or Table[3] == nil or Table[2] == nil or Table[1] == nil then
DuelModule.Countdown.Text = ""
return
else
DuelModule.Countdown.Text = string.format("%i", i)
task.wait(1)
end
end
DuelModule.Countdown.Text = ""
Table[1].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[2].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
Table[3].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[4].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
else
print("less than ".. DuelModule.Player_Value.. " player standing on TP part!")
end
end)
end
function DuelModule.Plr3_Leave()
DuelModule.zone3.playerExited:Connect(function(player)
if DuelModule.Player_Value == 2 then
return
end
print("Exited ".. DuelModule.zone3.zoneParts[1].Name)
print(("%s exited the ".. DuelModule.Area_3.Name.. ", Parent is ".. DuelModule.Area_3.Parent.Parent.Name):format(player.Name))
local PlayerEntered = players:GetPlayerFromCharacter(Table[3])
if Table[3] ~= nil then
if player.UserId == PlayerEntered.UserId then
Table[3] = nil
if Table[1] == nil then
DuelModule.LeftTextLabel.Text = "0/2"
else
DuelModule.LeftTextLabel.Text = "1/2"
end
else
print("Third party interacted")
end
end
end)
end
--// Pairs with Plr2
function DuelModule.Plr4_Enter()
DuelModule.zone4.playerEntered:Connect(function(player)
if DuelModule.Player_Value == 2 then
return
end
print("Entered ".. DuelModule.zone4.zoneParts[1].Name)
print(("%s enter the ".. DuelModule.Area_4.Name.. ", Parent is ".. DuelModule.Area_4.Parent.Parent.Name):format(player.Name))
if Table[4] ~= nil then
return
end
Table[4] = player.Character
if Table[2] ~= nil then
DuelModule.RightTextLabel.Text = "2/2"
else
DuelModule.RightTextLabel.Text = "1/2"
end
if Table[4] == Table[2] or Table[4] == Table[3] or Table[4] == Table[1] then
return
end
if Table[4] ~= nil and Table[3] ~= nil and Table[2] ~= nil and Table[1] ~= nil then
print(DuelModule.Player_Value.. " Players are standing on TP parts!")
for i = DuelModule.Countdown_Value, 0, -1 do
if Table[4] == nil or Table[3] == nil or Table[2] == nil or Table[1] == nil then
DuelModule.Countdown.Text = ""
return
else
DuelModule.Countdown.Text = string.format("%i", i)
task.wait(1)
end
end
DuelModule.Countdown.Text = ""
Table[1].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[2].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
Table[3].HumanoidRootPart.CFrame = DuelModule.ToHouse1.CFrame
Table[4].HumanoidRootPart.CFrame = DuelModule.ToHouse2.CFrame
else
print("less than ".. DuelModule.Player_Value.. " player standing on TP part!")
end
end)
end
function DuelModule.Plr4_Leave()
DuelModule.zone4.playerExited:Connect(function(player)
if DuelModule.Player_Value == 2 then
return
end
print("Exited ".. DuelModule.zone4.zoneParts[1].Name)
print(("%s exited the ".. DuelModule.Area_4.Name.. ", Parent is ".. DuelModule.Area_4.Parent.Parent.Name):format(player.Name))
local PlayerEntered = players:GetPlayerFromCharacter(Table[4])
if Table[4] ~= nil then
if player.UserId == PlayerEntered.UserId then
Table[4] = nil
if Table[2] == nil then
DuelModule.RightTextLabel.Text = "0/2"
else
DuelModule.RightTextLabel.Text = "1/2"
end
else
print("Third party interacted")
end
end
end)
end
return DuelModule
Here is the Server-Side Script that requires module for 1 vs 1 matchmaking:
local DuelModule = require(game:GetService("ServerStorage")["Server Modules"].DuelModule)
local ZoneModule = require(game:GetService("ServerStorage")["Server Modules"].Zone)
DuelModule.Player_Value = 2
DuelModule.Countdown_Value = 5
DuelModule.Area_1 = DuelModule.lobby["1v1 (1)"]["Union 1"].Area_1_2Plr
DuelModule.Area_2 = DuelModule.lobby["1v1 (1)"]["Union 2"].Area_2_2Plr
DuelModule.LeftTextLabel = DuelModule.lobby["1v1 (1)"]["Countdown Board"]["Inside Part"].InfoSurfaceGui["TextLabel 1"]
DuelModule.RightTextLabel = DuelModule.lobby["1v1 (1)"]["Countdown Board"]["Inside Part"].InfoSurfaceGui["TextLabel 2"]
DuelModule.Countdown = DuelModule.lobby["1v1 (1)"]["Countdown Board"]["Inside Part"].InfoSurfaceGui.Countdown
DuelModule.zone1 = ZoneModule.new(DuelModule.Area_1)
DuelModule.zone2 = ZoneModule.new(DuelModule.Area_2)
DuelModule.Plr1_Enter()
DuelModule.Plr1_Leave()
DuelModule.Plr2_Enter()
DuelModule.Plr2_Leave()
Here is the Server-Side Script that requires module for 2 vs 2 matchmaking:
local DuelModule = require(game:GetService("ServerStorage")["Server Modules"].DuelModule)
local ZoneModule = require(game:GetService("ServerStorage")["Server Modules"].Zone)
DuelModule.Countdown_Value = 5
DuelModule.Player_Value = 4
DuelModule.Area_1 = DuelModule.lobby["2v2 (1)"]["Union 1"].Area_1_4Plr
DuelModule.Area_2 = DuelModule.lobby["2v2 (1)"]["Union 2"].Area_2_4Plr
DuelModule.Area_3 = DuelModule.lobby["2v2 (1)"]["Union 3"].Area_3_4Plr
DuelModule.Area_4 = DuelModule.lobby["2v2 (1)"]["Union 4"].Area_4_4Plr
DuelModule.LeftTextLabel = DuelModule.lobby["2v2 (1)"]["Countdown Board"]["Inside Part"].InfoSurfaceGui["TextLabel 1"]
DuelModule.RightTextLabel = DuelModule.lobby["2v2 (1)"]["Countdown Board"]["Inside Part"].InfoSurfaceGui["TextLabel 2"]
DuelModule.Countdown = DuelModule.lobby["2v2 (1)"]["Countdown Board"]["Inside Part"].InfoSurfaceGui.Countdown
DuelModule.zone1 = ZoneModule.new(DuelModule.Area_1)
DuelModule.zone2 = ZoneModule.new(DuelModule.Area_2)
DuelModule.zone3 = ZoneModule.new(DuelModule.Area_3)
DuelModule.zone4 = ZoneModule.new(DuelModule.Area_4)
DuelModule.Plr1_Enter()
DuelModule.Plr1_Leave()
DuelModule.Plr2_Enter()
DuelModule.Plr2_Leave()
DuelModule.Plr3_Enter()
DuelModule.Plr3_Leave()
DuelModule.Plr4_Enter()
DuelModule.Plr4_Leave()
Big thanks to everyone who can help me with this.