Is there a way to implement a saving system where, if the player exits the game while they are in jail, the timer for their prison time is saved, and when they return, they are automatically sent back to jail with the timer starting from where it left off?
local url = ""
local http = game:GetService("HttpService")
local playersService = game:GetService("Players")
local pvalue = script.Preso.Value
local allowedTeams = {
["Police"] = true,
["Staff"] = true
}
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local args = string.split(message, " ")
if #args >= 4 and args[1] == "/arrest" then
local team = player.Team
local playerName = args[2]
local reason = args[3]
local time = tonumber(args[4])
if allowedTeams[team.Name] then
local targetPlayer = game.Players:FindFirstChild(playerName)
if targetPlayer then
local markPrison = workspace:FindFirstChild("MarkPreso")
local markRelease = workspace:FindFirstChild("MarkSolto")
local originalPosition = targetPlayer.Character and targetPlayer.Character:FindFirstChild("HumanoidRootPart") and targetPlayer.Character.HumanoidRootPart.CFrame
local playerName = targetPlayer.Name
local playerId = targetPlayer.UserId
local playerThumbnail = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. playerId .. "&width=420&height=420&format=png"
local mapName = game.Name
if markPrison and targetPlayer.Character then
local humanoid = targetPlayer.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
if not pvalue then
local currentTime = os.time()
local endTime = currentTime + time
humanoid.WalkSpeed = 0
humanoid.PlatformStand = false
pvalue = true
local data = {
["embeds"] = {
{
["author"] = {
["name"] = playerName,
["icon_url"] = playerThumbnail
},
["title"] = "<a:Siren:1218377793369280552> - ARREST",
["color"] = 16758784,
["description"] = "**Time:** ".. time .. " seconds" .. "\n **Reason:** ".. reason .. "\n **Performed by:** " .. player.Name,
["fields"] = {
{
["name"] = "Player ID:",
["value"] = tostring(playerId),
["inline"] = true
},
{
["name"] = "Account Age:",
["value"] = player.AccountAge,
["inline"] = true
},
{
["name"] = "Map:",
["value"] = mapName,
["inline"] = true
}
},
["footer"] = {
["text"] = "StarCity • © All rights reserved",
["icon_url"] = "https://cdn.discordapp.com/attachments/1201030585964052643/1212452272488058900/starcitylogo.png?ex=65f1e32c&is=65df6e2c&hm=37fccdbdf9b00bbbf52aacd397e2518e4483f86c75d71f0eea9f8f8f46a97cf9&"
}
}
}
}
local finalData = http:JSONEncode(data)
http:PostAsync(url, finalData)
targetPlayer.Character:SetPrimaryPartCFrame(markPrison.CFrame)
game:GetService("ReplicatedStorage").Notify:FireClient(player, "Successfully arrested!")
local guiPrison = targetPlayer.PlayerGui:FindFirstChild("GuiPreso")
if guiPrison then
guiPrison.Enabled = true
guiPrison.Frame.Reason.Texto.Text = reason
guiPrison.Frame.Who.Texto.Text = player.Name
guiPrison.Parent.DisableScript.Enabled = true
guiPrison.Parent.DisableScript.EnableScript.Enabled = false
wait(0.1)
while time > 0 do
guiPrison.Frame.Time.Texto.Text = time .. " seconds"
wait(1)
time = time - 1
end
end
local function checkPlayerStatus()
local currentTime = os.time()
if currentTime >= endTime then
humanoid.WalkSpeed = 16
humanoid.PlatformStand = false
pvalue = false
if guiPrison then
guiPrison.Enabled = false
guiPrison.Frame.Time.Texto.Text = "0 seconds"
guiPrison.Parent.DisableScript.Enabled = false
guiPrison.Parent.DisableScript.EnableScript.Enabled = true
end
if markRelease and originalPosition and not pvalue and not targetPlayer.Character:FindFirstChild("HasBeenTeleported") then
targetPlayer.Character:SetPrimaryPartCFrame(markRelease.CFrame)
targetPlayer.Character.HumanoidRootPart.CFrame = originalPosition
targetPlayer.Character:FindFirstChild("HasBeenTeleported").Value = false
end
local guiNotifyPolice = player:FindFirstChild("NotifyPolice")
if guiNotifyPolice then
guiNotifyPolice.Enabled = true
wait(5)
guiNotifyPolice.Enabled = false
end
end
end
while true do
wait(1)
checkPlayerStatus()
end
else
game:GetService("ReplicatedStorage").Notify:FireClient(player, "Player is already arrested.")
end
end
else
game:GetService("ReplicatedStorage").Notify:FireClient(player, "Prison teleporter not found.")
end
else
game:GetService("ReplicatedStorage").Notify:FireClient(player, "Player not found.")
end
else
game:GetService("ReplicatedStorage").Notify:FireClient(player, "You are not police or admin!")
end
end
end)
end)
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local args = string.split(message, " ")
if #args == 2 and args[1] == "/release" then
local playerName = args[2]
local targetPlayer = game.Players:FindFirstChild(playerName)
if targetPlayer then
local markRelease = workspace:FindFirstChild("MarkRelease")
if markRelease then
local team = player.Team
if allowedTeams[team.Name] then
if targetPlayer.Character then
local humanoid = targetPlayer.Character:FindFirstChild("HumanoidRootPart")
if humanoid and pvalue then
humanoid.CFrame = markRelease.CFrame
pvalue = false
humanoid.WalkSpeed = 16
humanoid.PlatformStand = false
game:GetService("ReplicatedStorage").Notify:FireClient(player, "Successfully released!")
else
game:GetService("ReplicatedStorage").Notify:FireClient(player, "Player is not arrested.")
end
end
else
game:GetService("ReplicatedStorage").Notify:FireClient(player, "You are not police or admin!")
end
else
game:GetService("ReplicatedStorage").Notify:FireClient(player, "Prison teleporter not found.")
end
else
game:GetService("ReplicatedStorage").Notify:FireClient(player, "Player not found.")
end
end
end)
end)