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:
01 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "ServerSavesTest1" ) |
02 |
03 | print ( "Creating Stats..." ) --All prints are to show where the script is and when any problems occur. |
04 |
05 | local Roles = Instance.new( "Folder" ) --Folder to hold a few items that I want limited. |
06 | Roles.Name = "PlayerRoles" |
07 | Roles.Parent = game.ReplicatedStorage |
08 |
09 | local ltd 1 = Instance.new( "NumberValue" ) --First item to be limited, only doing 3 to test. |
10 | ltd 1. Name = "GiantFireball" |
11 | ltd 1. 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. |
12 | ltd 1. Parent = Roles |
13 |
14 | local ltd 2 = Instance.new( "NumberValue" ) |
15 | ltd 2. Name = "GiantWaterWave" |
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()
:
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 |
03 | local CurrentVersion = "v1.0" |
04 |
05 | local AssetID = 2355087160 |
06 | local AssetInfo = MarketplaceService:GetProductInfo(AssetID, Enum.InfoType.Asset) -- GetProductInfo() has two parameters, the asset's id and the type |
07 | local Description = AssetInfo.Description -- this returns as string |
08 |
09 | --I use a loop to check if the description (updatedVersion) version matches with the CurrentVersion: |
10 | while true do |
11 | Description = AssetInfo.Description |
12 | local updatedVersion = string.sub(Description, 1 , 4 ) -- gets the first 4 string from the description |
13 | if updatedVersion ~ = CurrentVersion then |
14 | --kick players |
15 | end |
16 | wait( 5 ); |
17 | 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.