Saving Arrest Records to a Datastore?

I’m currently in the process of producing a tablet system that holds all the current units and players within a game etc.

I’m stunted on how i would create an Arrest Record for a player that would be saved by a DataStore, and creates a TextLabel with the Arresting Player, and then a Reason for the arrest as it’s text. Is it possible to save Text from a TextLabel and then Load it when the player joins?

Any help is greatly appreciated as I’ve researched but found nowhere to even start from.

1 Like

first i would make a folder inside of each player named Arrest_Records and then make a function inside the arresting script and make a function like this

local function MakeArrest(msg,plr)
   local val = Instance.new("StringValue")
   val.Name = plr.Name
   val.Value= msg
   val.Parent = plr:FindFirstChild("Arrest_Records")
end

the function would be called like this

MakeArrest("you did the bad", plr) -- the plr is the player object

and then the datastore would be something like this

	local dss = game:GetService("DataStoreService")
	
	local DataStore = dss:GetDataStore("data")
	
	local function LoadData(plr)
		local folder = Instance.new("Folder")
		folder.Name = "Arrest_Records"
		folder.Parent = plr
		
		local tries = 0 
		local s 
		local data
		
		repeat
			s = pcall(function()
				data = DataStore:GetAsync(plr.UserId)
			end)
		until tries == 3 or s
		
		if s and data then
			for i , msg in pairs(data) do
				local stringv = Instance.new("StringValue")
				stringv.Value = msg
				stringv.Name = plr.Name
				stringv.Parent = folder
			end
		end
		
		return true
		
	end
	
	
	local function saveData(plr)
		if not plr:FindFirstChild("Arrest_Records") then return false end
		local folder = plr:FindFirstChild("Arrest_Records")
		local tries = 0 
		local s 
		repeat
			s = DataStore:UpdateAsync(plr.UserId,function(data)
				data = {}
				
				for i , v in pairs(folder:GetChildren()) do
					data[v.Value] = v.Value
				end
				
				return data
				
			end)
		until tries == 3 or s 
		return true
	end



game.Players.PlayerAdded:Connect(LoadData)

game.Players.PlayerRemoving:Connect(saveData)

game:BindToClose(function()
	for i,v in pairs(game.Players:GetPlayers()) do
		v:Kick()
	end
	wait(3)
end)

hope this helped!

1 Like

I’m a bit confused as to what

is achieving. Would this be the text i was talking about?

yes it would be you can fire a remote event so example

– client

local text = TEXTBOXHERE

local plrName = playerthatgotarrested_Name

game.ReplicatedStorage.RemoteEvent:FireServer(text,plrName)

– server

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr , msg , arrestedplr)
	if not game.Players:FindFirstChild(arrestedplr) then return end

	MakeArrest(msg,game.Players:FindFirstChild(arrestedplr))
end)
1 Like

Ahh okay i understand now. Thank you! This helps me out alot.

1 Like