Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

local DataStore = game:GetService("DataStoreService"):GetDataStore("NicuWolfSlot1")


game.Players.PlayerAdded:connect(function(player)
	local viewkey = "Colorsfor"..player.userId
	local Savedstuff = DataStore:GetAsync(viewkey)
	
if Savedstuff then
	script.Parent.Text="Load"
end

end)

script.Parent.MouseButton1Click:connect(function(player)
	
	local viewkey = "Colorsfor"..player.userId
	local Savedstuff = DataStore:GetAsync(viewkey)

	if Savedstuff then
		
		
		script.Parent.Parent.Parent.Continue.Visible = true
		script.Parent.Parent.Visible = false
		print ("It's okay den")
	
	
	else
		
		print ("Nothing here!")
		return 
		
	end
end)

1 answer

✓ Accepted answer

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:

local data = game:GetService("DataStoreService"):GetDataStore("Testing")
data:SetAsync("ColorTest","blue") -- 'blue' being our color key

-- A dictionary of what we can compare our saved key to
local Colors = {
	['red'] = Color3.new(1,0,0),
	['green'] = Color3.new(0,1,0),
	['blue'] = Color3.new(0,0,1),
}

-- Get the saved key from the Colors table
local SavedColor = Colors[data:GetAsync("ColorTest")]

-- Print it
print(SavedColor)

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

This discussion is preserved as it was. New answers, comments, and votes are closed.