So I'm trying to create an automated system to handle updating values across all servers for items with limited numbers. Right now I have it set w/ a custom key and the values are created and put in replicatedstorage. Everything I'm doing right now is just for testing purposes until I figure out how exactly I want to handle where everything is and how to handle them.
The idea is that certain roles/abilities/tools are limited to a certain number of players. Now my question is: Is this doable and if so should I do it or should I try another method?
My code right now is as following:
local DataStore = game:GetService("DataStoreService"):GetDataStore("ServerSavesTest1")
print("Creating Stats...") --All prints are to show where the script is and when any problems occur.
local Roles = Instance.new("Folder") --Folder to hold a few items that I want limited.
Roles.Name = "PlayerRoles"
Roles.Parent = game.ReplicatedStorage
local ltd1= Instance.new("NumberValue") --First item to be limited, only doing 3 to test.
ltd1.Name = "GiantFireball"
ltd1.Value = 0 --This will be a userid of the player who retrieves this power. Limited to one player at a time, I plan to check when the user who has this joins the game and give them it.
ltd1.Parent = Roles
local ltd2 = Instance.new("NumberValue")
ltd2.Name = "GiantWaterWave"
ltd2.Value = 0
ltd2.Parent = Roles
local ltd3 = Instance.new("NumberValue")
ltd3.Name = "Meteorites"
ltd3.Value = 0
ltd3.Parent = Roles
--Datastores
local key = "GameRoles" --Just a test key, is this doable?
local storeditems = DataStore:GetAsync(key)
if storeditems then
else
local items = {ltd1.Value,ltd2.Value,ltd3.Value}
DataStore:SetAsync(key, items)
end
print("Waiting to start...")
wait(5)
enabled = true
print("Save Function Started!")
repeat wait(10) --Wait time of 10 so I don't have to wait forever to leave and rejoin.
print("Saving Stats...")
local stats = game.ReplicatedStorage:WaitForChild("PlayerRoles")
local items = {stats:WaitForChild("GiantFireball").Value, stats:WaitForChild("GiatWaterWave").Value,
stats:WaitForChild("Meteorites").Value}
local key = "GameRoles"
DataStore:SetAsync(key, items)
for i,v in pairs(stats:GetChildren()) do print(v.Name.." user: "..v.Value) end
print("Stats saved!")
until enabled == false

2 comments
So like a live update
Yeah, sorry for late replies. I end up asking questions then forget to check them. I figured out a solution.