Greetings my fellow ROBLOX scripters and developers,

As a person new to creating games on this platform, I have had lots of help to create this sophisticated prison system which I want to work beautifully, but unfortunately I have run out of help and I am looking for a helpful person who would like to help me with this. My script currently has a GUI which is brought up when the tool is opened and you are near a player, and detains them when you press E. Then the only relevant option is to press arrest where there is a GUI for the amount of time you want them to be in jail for and a reason. And then after that the player who is being arrested should get teleported to the prison area for the suggested time, and then respawned. However, the issue is that when you press arrest, the player is only respawned and not put into jail. And the other issue is that the tool only works once - it stops working after you have used it on someone. I will put my script below (it is long) but if you know a possible solution please don't hesitate to leave a reply.

--services
local players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Http = game:GetService("HttpService")
local RunService = game:GetService("RunService")
local MarketplaceService = game:GetService("MarketplaceService")
local webhook = ""
--events
local prison = ReplicatedStorage:WaitForChild("prison")

--vars
local PrisonSystem = workspace:WaitForChild("PrisonSystem")

local processed = {}--{"player", "connection", "reason", "time", "arrestee"}

local function completeTime(player)
	local reset = false
	player.CharacterAdded:Connect(function()
		reset = true
	end)
	while not reset and wait(1) do
		if not players:FindFirstChild(player.Name) or not player.Character then
			break
		end
		for i,v in pairs(processed) do --if player is removed from processed index will adapt
			if processed[i][1].Name == player.Name then
				processed[i][4] = processed[i][4] - 1
				prison:FireClient(player, "arrest", processed[i][3], processed[i][4], processed[i][5])
			end
			if processed[i][4] <= 0 then
				processed[i] = nil
				player:LoadCharacter()
				break
			end
		end
	end
end

local function establishCell(player)
	local cells = PrisonSystem:WaitForChild("Cells"):GetChildren()
	local connection
	connection = player.CharacterAdded:Connect(function()
		local processing = false
		for i,v in pairs(processed) do
			if processed[i][1].Name == player.Name then
				processing = true
			end
		end
		wait(1)
		player.Character.HumanoidRootPart.CFrame = cells[math.random(1,#cells)].CFrame
		completeTime(player)
	end)
	if players:FindFirstChild(player.Name) then
		player:LoadCharacter()
	end
	return connection
end

local function establishConnection(player)
	for i,v in pairs(processed) do 
		if processed[i][1].Name == player.Name then
			establishCell(player)
		end
	end
end

--[[
local function postArrestLog(log) 
	assert(typeof(log) == "string", "Log needs to be a string")
	local response = Http:RequestAsync({
		Url = "https://623b9506.eu-gb.apiconnect.appdomain.cloud/usar/arrest",
		Method = "POST",
		Headers = {
			["Content-Type"] = "application/json",
			["X-IBM-Client-Id"] = "d67d9e82-f27f-4b42-bd46-3031c3ac234f"	
		},
		Body = Http:JSONEncode({message = log})	
	})
	print(response.Success, response.StatusCode)
end
]]
local whiteListedGroups = {
	{"9459284", 247}, --AZNU HQ
	{"9734974", 2} --MP
}
local function checkPlayer(player)
	for i,v in pairs(whiteListedGroups) do
		if player:IsInGroup(whiteListedGroups[i][1]) and player:GetRankInGroup(whiteListedGroups[i][1]) >= whiteListedGroups[i][2] then
			return true
		end
	end
	print("Player is not whitelisted")
	return false
end

local detainedPlayers = {}
prison.OnServerEvent:Connect(function(player, status, reason, _time, holdingPlayer, auto)
	if not checkPlayer(player) then return end
	if player and player.Character and holdingPlayer and holdingPlayer.Character then
		local mag = (player.Character.HumanoidRootPart.Position - holdingPlayer.Character.HumanoidRootPart.Position).Magnitude
		if mag > 10 then
			return
		end
	end
	for i,v in pairs(processed) do --if player is removed from processed index will adapt
		if processed[i][1].Name == holdingPlayer.Name then
			return
		end
	end
	if status == "detain" then
		holdingPlayer.Character.Humanoid.WalkSpeed = 0
		prison:FireClient(holdingPlayer, status)
		detainedPlayers[holdingPlayer.Name] = holdingPlayer.Character.Head.Position
		holdingPlayer.Character.Humanoid.Died:Connect(function()
			detainedPlayers[holdingPlayer.Name] = nil
		end)
	elseif status == "release" then
		detainedPlayers[holdingPlayer.Name] = nil
		holdingPlayer.Character.Humanoid.WalkSpeed = 16
		prison:FireClient(holdingPlayer, status)
	elseif status == "arrest" then
		detainedPlayers[holdingPlayer.Name] = nil
		if _time > 900 then
			_time = 900
		elseif _time < 1 then
			_time = 1
		end
		local date = os.date("!*t")
		
		local embed = {
			['embeds'] = {{
				["title"] = "**SERVER ARREST REPORT**",
				["description"] = "Situation: " ..holdingPlayer.Name.. " was arrested by " ..player.Name,
				["color"] = 16711680,
				["thumbnail"] = {
							url = players:GetUserThumbnailAsync(holdingPlayer.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
						},		
				["fields"] = {
						{
							name = "Arrested Profile Link",
							value = "https://www.roblox.com/users/" ..holdingPlayer.UserId.. "/profile"
						},
						{
							name = "Reason:",
							value = reason
						},
						{
							name = "Sentence:",
							value = tostring(_time).." seconds"
						}
						},				
				["footer"] = {
							text = "Arrested at Aldin Keep " ..date.month.. "/" ..date.day.. "/" ..date.year.. " at " ..date.hour.. ":" ..date.min.. " UTC"
							--"..MarketplaceService:GetProductInfo(game.GameId).Name.."
						}
			}}
		}

		Http:PostAsync(webhook, Http:JSONEncode(embed)) 
		table.insert(processed, {holdingPlayer, establishCell(holdingPlayer), reason, _time, player.Name})
	end
end)

RunService.Heartbeat:Connect(function()
	for _player, pos in pairs(detainedPlayers) do
		local player = players:FindFirstChild(_player)
		if player and player.Character then
			local mag = (player.Character.Head.Position - pos).Magnitude
			if mag > 50 then
				detainedPlayers[_player] = nil
				player:Kick("Leaving detained original position, automatic 15 minute arrest in place upon being in server")
			end
		end
	end
end)

players.PlayerAdded:Connect(function(player)
	establishConnection(player)
end)