Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Saving Limited items in datastores?

Asked by 5 years ago

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
0
So like a live update awesomeipod 607 — 5y
0
Yeah, sorry for late replies. I end up asking questions then forget to check them. I figured out a solution. OneTruePain 191 — 5y

1 answer

Log in to vote
2
Answered by
hellmatic 1523 Moderation Voter
5 years ago
Edited 5 years ago

Yesterday I was able to create a custom server shutdown message by using a hacky method (doesn't involve data stores).

I uploaded a asset to ROBLOX: https://www.roblox.com/library/2355087160/SM-UPDATE The description has important information: the updated version of the asset and the shutdown message.

With MarketplaceService, you can get the asset's description by using GetProductInfo():

local MarketplaceService = game:GetService("MarketplaceService")

local CurrentVersion = "v1.0"

local AssetID = 2355087160
local AssetInfo = MarketplaceService:GetProductInfo(AssetID, Enum.InfoType.Asset) -- GetProductInfo() has two parameters, the asset's id and the type
local Description = AssetInfo.Description -- this returns as string

--I use a loop to check if the description (updatedVersion) version matches with the CurrentVersion:
while true do
    Description = AssetInfo.Description
    local updatedVersion = string.sub(Description, 1, 4) -- gets the first 4 string from the description
    if updatedVersion ~= CurrentVersion then 
        --kick players
    end
    wait(5);
end

The script basically checks if the version matches the description version and if not kicks all players.

I suggest to upload a asset to ROBLOX that contains the updated vaues and use the description version I used above. If the versions don't match, load the asset in with InsertService, get the new values and replace the old ones with those.

0
Not quite what I meant, but I gave it a try for something else and it helped. Thanks! OneTruePain 191 — 5y
Ad

Answer this question