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

Is it possible for Data Stores to be checked in other scripts?

Asked by 9 years ago

Honestly, i'm still having trouble with these darned Data Stores,

THIS IS A NORMAL SCRIPT WITHIN A GUI

Usually, how it works, when you leave the game, it's supposed to save the colors of the morph When you come back, if you've saved anything, it would change the gui's text to "LOAD" and it would lead you to a Continue screen

However, even if i did save, it still doesnt show as anything.

Either it doesnt save, something's gone wrong, or i wrote this script wrong:

And this may sound silly too, since it's one of the less harder scripts.

( Here is the save script: https://scriptinghelpers.org/questions/22446/why-wont-this-script-work )

( Also how do you activate a Localscript within a normal script? Just a quick question)

Sorry if i've been bothing anyone here with these scripts only relating to Data Stores, i've been working on this for awhile, and i want to get this done ASAP!

01local DataStore = game:GetService("DataStoreService"):GetDataStore("NicuWolfSlot1")
02 
03 
04game.Players.PlayerAdded:connect(function(player)
05    local viewkey = "Colorsfor"..player.userId
06    local Savedstuff = DataStore:GetAsync(viewkey)
07 
08if Savedstuff then
09    script.Parent.Text="Load"
10end
11 
12end)
13 
14script.Parent.MouseButton1Click:connect(function(player)
15 
View all 33 lines...

1 answer

Log in to vote
3
Answered by 9 years ago

ROBLOX's data store system is very dynamic. There are a lot of things you can, and can't do. Here are a few:

Saving

Now, It's important to know that when using data store, we're storing information outside of ROBLOX servers. Meaning anything specific to ROBLOX Lua, will be considered non-existent (or in Lua terms, "nil"). A few examples of data that cannot be compiled to data store, are these:

1: userdatas (i.e, Instances, Vector3.new, CFrame.new, BrickColor.new, etc)

2: functions

3: mixed table dictionaries / arrays (these may not break, but will not save properly. Single style tables save just fine).

Choices

This basically leaves you with the following choices of data to be saved:

- Numbers

- Tables (of specific record style)

- Strings (most commonly used)

- Booleans

And of course, a nil value.

Solution

So, with the above choices we have, we can make a function that converts incomprehensible data to something ROBLOX Lua understands. Here's a small example of how this could work:

01local data = game:GetService("DataStoreService"):GetDataStore("Testing")
02data:SetAsync("ColorTest","blue") -- 'blue' being our color key
03 
04-- A dictionary of what we can compare our saved key to
05local Colors = {
06    ['red'] = Color3.new(1,0,0),
07    ['green'] = Color3.new(0,1,0),
08    ['blue'] = Color3.new(0,0,1),
09}
10 
11-- Get the saved key from the Colors table
12local SavedColor = Colors[data:GetAsync("ColorTest")]
13 
14-- Print it
15print(SavedColor)

Hope this helped. Let me know if you have any questions.

Ad

Answer this question