Saving array to datastore

Hello,

Currently I am working on a Admin Panel. I want that when you kick someone that action is being saved so for example a manager can look back in the logs who kicked that player. For that I need to save 4 things, the action (kick), the moderator, the reason and the date. I was trying to save this via an Array, but then I get the error “DataStoreService: CantStoreValue: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters.”. How do I save an array or multiple values to a datastore?

local DataBase = game:GetService("DataStoreService"):GetDataStore("VJAdminDB")

script.Parent.MouseButton1Click:Connect(function()
	local ProfileKey = "Profile_5149314582_" .. game.GameId
	

	local ProfileData = { 
		"Kick", "VervelendJong (1723768065)", "System Test", DateTime.now()
	}

	local Success, Failure = pcall(function()
		DataBase:SetAsync(ProfileKey, ProfileData)
	end)
	
	if Success then
		print("Success")
	else
		print("Fail")
	end
end)

A simple way to store an array in a datastore is using JSON encoding and decoding HttpService | Documentation - Roblox Creator Hub

local String = HttpService:JSONEncode(Table) -- Encoding a table to a string
-- This string can then be saved in a datastore


local Table = HttpService:JSONEncode(String) -- Decoding the string back to a table

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.