I came up with this script which basically assigns an Id to each connection that I want control of, so Touched, CharacterAdded ecc Events on roblox.
for _, Part in ipairs(Checkpoints) do
if Part:IsA("Part") and tonumber(Part.Name) then
Connections[UserId] = Part.Touched:Connect(function(Hit)
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
local stage = leaderstats and leaderstats:FindFirstChild("Stage")
if stage and stage.Value == tonumber(Part.Name) - 1 then
stage.Value += 1
end
end
end)
end
end
Is this bad since it makes a new connection per player? I wanna know I’ve asked a few AI Models and I got told that it is not good practive to make connections per player but I wanna hear the opinion from others.
Why would you want a connection per player for specifically this script? Pretty sure it would work perfectly fine with a single Touched connection for each part
Im assuming these checkpoints are persistent and dont get destroyed, in which case there shouldn’t be any problem with having a few connections. If the parts does get destroyed however, the connections will automatically be disconnected when the Destroy() is called