How to make Jail system?

How could I go about making a jail system with datastore? So if the player leaves the game while in jail and then re-joins, the player goes back to jail.

Any help appreciated!

You can just use a boolean value to save whether the player was in jail or not. Then you can get the value of that boolean when the player joins back.

local inJail = false -- false or true

local DataStoreService = game:GetService("DataStoreService")
 
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
 
local success, errorMessage = pcall(function()
	experienceStore:SetAsync("User_1234", inJai)
end)
if not success then
	print(errorMessage)
end

1 Like

Preferably, you would check the time with DateTime.now to see if they’re still in jail.

Assuming that a player leaves for hours and the jail time is just a few minutes, this would skip the jail time when the player joins back.