Hi,
I’m not sure if that is the correct way to ask the question however what I’m trying to ask is how I go about creating a sort of “criminal record system” in which one player can create a report about someone, and it saves to the datastore.
However, I’m unsure how to create multiple reports for the same person. I’ve looked around on the wiki but can’t seem to find out how to do it.
I understand this isn’t a request site however I would love to be pointed in the right direction and given a source I can read up on, or an example script.
Thanks in advance.
Lua uses tables as its data structure. They are essentially the same as any other table, with keys and values. We can assign a data store key to a table, which, in itself, contains multiple keys and values.
Tables are created with the table constructor expression, which, in it simplest form, is written as {}
.
-- Declare local t and assign it to a new table. local t = {} -- Assign the key "foo" to value "bar". t["foo"] = "bar" -- Identical to t["baz"] = "qux", but syntactically sweeter. t.baz = "qux" -- We can use any data type as a key, except nil, and any data type as a value. t[false] = 123 -- Get and print the value associated with certain keys. print(t.foo) --> bar print(t[false]) --> 123 print(t["baz"]) --> qux -- Table fields evaluate to nil when they are not initialised. print(t.boo) --> nil -- We can assign nil to a table field to delete it. t[false] = nil
In your system, each Player might have their own table of criminal records that you get and update appropriately.
I don't really know if the script below me will work. But I have a data store that I will use in the script below. Plus I am assuming tables (Roblox tables) V.S. Strings, Ints, ETC ... Work similar in datastores.
-- Make a Table, Define the DataStore local Record = {"I am not a criminal yet", "The game is still loading"} local DataStore = game:GetService("DataStoreService"):GetDataStore("Example Data Store") -- When the player joins the game then game.Players.PlayerAdded:Connect(function(Player) -- The player who joined the game. local ID = "Record".."-"..Player.UserId local SavedData = nil pcall(function() -- If there is an error don't stop running the script!!! Keep going! SavedData = DataStore:GetAsync(ID) end) if SavedData ~= nil then -- If we have no more data to load then ... We are done :D ah ... Currency.Value = SavedData print("Data Loaded") else Currency.Value = 0 print("A new player has joined the game") end end) -- When the player leaves the game then save their data game.Players.PlayerRemoving:Connect(function(Player) -- That defines the player local ID = "Record".."-"..Player.UserId DataStore:SetAsync(ID, Record) end) -- If the game gets shut down then: game:BindToClose(function() -- Notice we don't have player in there ;). for i, Player in pairs(game.Players:GetPlayers()) do if Player then Player:Kick("This game is shutting down, It might be updating!") end end wait(3) -- The clock is ticking. Make that whatever you want. end)
Hope that helps ;D.