You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I am currently working on a system and I need to keep track of multiple RBXScriptConnection (aka events) related to the player’s current character
function MovementService:AddPlayer(userId:number)
local listener:userData = self.movementListeners[userId]
if not listener then
local character = Players:GetPlayerByUserId(userId).Character or Players:GetPlayerByUserId(userId).CharacterAdded:Wait()
listener = {Character = character, Connections = {}}
self.movementListeners[userId] = listener
end
end
-
What is the issue? Include screenshots / videos if possible!
I store a RBXScriptConnection instance in a table. However, when the player dies, I update the table to “link” the new character instead. But, since it’s a new character, I have to update the connection. That means I have to severe it and create a new one.
function MovementService:UpdateCharacter(userId:number)
local listener:userData? = self.movementListeners[userId]
if not listener or not listener.Connections then return end
local newCharacter = Players:GetPlayerByUserId(userId).Character or Players:GetPlayerByUserId(userId).CharacterAdded:Wait()
local existingConnections = self.movementListeners[userId].Connections
listener = {Character = newCharacter, Connections = existingConnections} --trouble line. ExistingConnections is ofc wrong, just put it here to showcase the trouuble
self.movementListeners[userId] = listener
end
But now the issue: as said, I have to severe the existing connections and make new ones, but since connections do not have any name, I can’t know which one is what and create a new one. Is there a way to identify a connection or to find a connection’s “name” even tho it doesn’t have one?
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Looking online for months now, but I have been asking myself this question for years. And it has finally come to a point where I can’t dodge this issue. I am completely lost