Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Proper way to use connections?

Asked by 4 years ago
Edited 4 years ago

Right now a lot of my code variable declaration looks like this:

--Connections--
local rbDownConn = nil
local rbUpConn = nil
local lbDownConn = nil
local lbUpConn = nil
local heartbeat = nil
local keyDetection = nil

--When equip--
heartbeat = RunService.Heartbeat:Connect(makeSpread)

--When unequip--
if heartbeat then heartbeat:Disconnect() end

I connect them all in .equip and disconnect in .unequip of my tool. But... should I even do this? Is this something ok to do or I can just use :connect and expect tool internal to clear connections on unequip?

Just something I can't find info about

0
Sure, that's fine, as long as that is your goal, to only call `makeSpread()` while tool is equipepd programmerHere 371 — 4y
0
What you're doing is fine, and is probably a more recommended way of going about this than what I've seen other people try and do in the past. In fact, I use a very similar technique for updating objects and when the objects are gone I just disconnect the event. CeramicTile 847 — 4y
0
Ok tnx for the replies I just thought keeping a lot of connections might not be really good for memory ItsNimbusCloud 66 — 4y

Answer this question