Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to keep a player in jail even if the player leaves the game? [Not answered]

I want to keep the player in jail even if the player leaves the game Here is the script for the arrest system

------------------------------------------------------
---------- | ARREST_MAIN | MAX_Y | CODE | ------------
------------------------------------------------------

game.Players.PlayerAdded:connect(function(plr)
	if plr:WaitForDataReady() then
		local v = Instance.new("IntValue")
		v.Name = "Arrested"
		v.Parent = plr
		plr.Arrested.Value = plr:LoadNumber("ArrestedV")
	
		if plr.Arrested.Value > 0 then
			plr.TeamColor = BrickColor.new("Lapis")
			plr:LoadCharacter()
		end
		plr.ChildAdded:connect(function(c)
			if c.Name == "Arrested1" then
				plr.TeamColor = BrickColor.new("Lapis")
				plr:LoadCharacter()
				if plr.PlayerGui:FindFirstChild("MainFrame") then
					plr.PlayerGui:FindFirstChild("MainFrame").Control.Visible = false
				end
				for i,v in pairs(plr.Backpack:GetChildren()) do
					if v:IsA("Tool") or v:IsA("HopperBin") then
						v:Destroy()
					end
				end
			end
		end)
	end
end)


while true do 
	wait(1)
	for i,v in pairs(game.Players:GetChildren()) do
		if v.TeamColor == BrickColor.new("Lapis") then
			v.Arrested.Value = v.Arrested.Value - 1
			v:SaveNumber("ArrestedV", v.Arrested.Value)
			if v.Arrested.Value < 0 then

				v:SaveNumber("ArrestedV", v.Arrested.Value)
				v.TeamColor = BrickColor.new("Maroon")
				
				v:LoadCharacter()
			end
		end
	end
end

------------------------------------------------------
---------------------- | END | -----------------------
------------------------------------------------------

I tried making a datastore but that didn't work Here is the datastore script

local DataStoreService = game:GetService("DataStoreService")
local Arreststore = DataStoreService:GetDataStore("Arrestsaving")

game.Players.PlayerAdded:Connect(function(player)
	pcall (function()
		local Arrested = Instance.new("IntValue",player)
		Arrested.Name = "Arrested"
		Arrested.Value = Arreststore:GetAsync(player.UserId) or 0
		Arrested.Changed:Connect(function()
		    Arreststore:SetAsync(player.UserId,player.Arrested.Value)
		    print("Time saved")
		end)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	pcall (function()
	Arreststore:SetAsync(player.UserId,player.Arrested.Value)
	print("Time saved")
end)

2 comments

0

DataStores

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.