Im new to modules.
Ever since I added modules to my game, it reached a ping of 500.
I use the modules to setup game modes during a round. Once that round is completed and another gamemode is chosen, a new module is turned on… there are now 2 modules running at the same time (atleast what I think is happening) in which one of them isn’t even being used.
Now imagine that 5 times (5 different modules).
_
My question is, can you turn them off as if it was never turned on before? Are the modules to blame for the high ping?
If I use conditionals in the code, such as inside a ‘touched:Connect(function())’ wouldn’t that mean the function will continue to run everytime the part is touched?
_
Here is what is contained in the one of the modules:
local CheckpointSystem = {}
local plrs = game:GetService("Players")
local tm = game.Teams
local rs = game:GetService("ReplicatedStorage")
local ss = game:GetService("ServerStorage")
local sbe = ss:WaitForChild("ServerBindableEvents")
local lastcheckpoint = {}
local recent = {}
function CheckpointSystem.enableCheckpoints(a, chosenmap)
delay(1, function()
table.clear(lastcheckpoint)
rs.RemoteEvents.SendGamemode:FireAllClients("Checkpoints")
for i, v in pairs(plrs:GetPlayers()) do
lastcheckpoint[v] = 1
end
if chosenmap:FindFirstChild("Checkpoints") then
for i, v in pairs(chosenmap.Checkpoints:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function(touched)
if plrs:GetPlayerFromCharacter(touched.Parent) then
local plr = plrs:GetPlayerFromCharacter(touched.Parent)
if touched.Parent:IsA("Model") and plr.Team ~= nil then
if tonumber(v.Name) > lastcheckpoint[plr] then
rs.RemoteEvents.InGamePlrUpdates:FireAllClients(plr.DisplayName, 3, tonumber(v.Name)-1)
lastcheckpoint[plr] = tonumber(v.Name)
end
end
end
end)
end
end
end
if chosenmap:FindFirstChild("Deathblocks") then
for i, v in pairs(chosenmap.Deathblocks:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function(touched)
if plrs:GetPlayerFromCharacter(touched.Parent) then
local plr = plrs:GetPlayerFromCharacter(touched.Parent)
if touched.Parent:IsA("Model") and plr.Team ~= nil then
if chosenmap:FindFirstChild("Checkpoints") then
touched.Parent:MoveTo(chosenmap.Checkpoints[lastcheckpoint[plr]].Position)
end
end
if not table.find(recent, plr.Name) then
table.insert(recent, plr.Name)
rs.RemoteEvents.InGamePlrUpdates:FireAllClients(plr.DisplayName, 1)
wait(1)
table.remove(recent, table.find(recent, plr.Name))
end
end
end)
end
end
end
end)
end
plrs.PlayerAdded:Connect(function(plr)
if tm:FindFirstChild("InGame") then
if plr.Team ~= nil then
lastcheckpoint[plr] = 1
end
end
end)
return CheckpointSystem
This is one of the shorter modules, but they all use this code above… should modules be this long? Or am I using modules incorrectly?
Any feedback is appreciated.