I have a jail script, unfortunately I don’t know how I would disconnect the function, here is the code
function module:jailPlayer(player)
local jailClone = jail:Clone()
jailClone.Parent = workspace
jailClone.SpawnPart.Position = player
local listener
listener = player.CharacterAdded:Connect(function()
player.Character.HumanoidRootPart.CFrame = jailClone.PrimaryPart.CFrame
end)
player:LoadCharacter()
end
function module:unjailPlayer(player)
-- disconnect the listener function somehow
end
A connection has a :Disconnect() method. To make this work, store these connections in a cache like this:
local jailcache = {}
function module:jailPlayer(player)
if jailcache[player] then return end
local jailClone = jail:Clone()
jailClone.Parent = workspace
jailClone.SpawnPart.Position = player
jailcache[player] = player.CharacterAdded:Connect(function()
player.Character.HumanoidRootPart.CFrame = jailClone.PrimaryPart.CFrame
end)
player:LoadCharacter()
end
function module:unjailPlayer(player)
if jailcache[player] then
jailcache[player]:Disconnect()
jailcache[player] = nil
end
end