Advertisement
CluelessDev

Seemingly a bug with disconnecting connections created by module.

Aug 9th, 2022 (edited)
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1. --* Prevents players w/o premission from entering zone through its entrances (if any),
  2. --* And allows handling if un-authorized entrance happens
  3.  
  4. --> Function that creates the connection ↓
  5. function module.GatekeepZone(zone, entrancesBlocks: table, collisionGroup: string): nil
  6.     -- ommited code
  7.     for _, entranceBlock: BasePart in zone.EntranceBlocks do
  8.         entranceBlock.CanCollide = true
  9.  
  10.         PhysicsService:SetPartCollisionGroup(entranceBlock, zone.CollisionGroup)
  11.        
  12.       --> logic chunks I'm having problems with. ↓
  13.        local conn = entranceBlock.Touched:Connect(function(theOtherPart: BasePart)
  14.             print("touched")  --> will print EVEN AFTER DISCONNECTION
  15.  
  16.             local Character: Model = theOtherPart.Parent
  17.             local Player: Player   = if Character then Players:GetPlayerFromCharacter(Character) else nil
  18.             if not Player then return end
  19.            
  20.             --#! Debounce if player is in CG already ↓
  21.             local inCollisionGroup: boolean = PhysicsService:CollisionGroupContainsPart(zone.CollisionGroup, Character.HumanoidRootPart)
  22.             local allowedInZone: boolean    = table.find(zone.AllowedPlayers, Player)
  23.        
  24.             if allowedInZone  and not inCollisionGroup then  
  25.                 SetModelDescendantsCollisionGroup(Character, zone.CollisionGroup)
  26.  
  27.             elseif not allowedInZone then
  28.                 SetModelDescendantsCollisionGroup(Character, "Default")
  29.             end
  30.         end)
  31.      
  32.         table.insert(entrancesTrovesArray[zone], conn)  
  33.  
  34.       -- ommited code
  35.     end
  36.    
  37. --> --> Function that attempts to disconnect the connection ↓
  38. --* Opens gatekept zone and removes any gatekeeping behavior from it.
  39. function module.OpenGatekeptZone(zone, shouldRemoveCollisionGroup: boolean)  --> clean up function
  40.      -- Ommited code
  41.  
  42.     for _, conn: RBXScriptConnection in entrancesTrovesArray[zone] do --> iterating through all conns to clean them
  43.         conn:Disconnect()  --> SHOULD clean the connection, and even appears as disconnected!
  44.         print(conn.Disconnected)  --> false / which bumms me out, cause it is indeed disconnected!
  45.     end
  46. end
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement