How to save unsupported values in datastore easily

Sorry, but using too many functions is really a bad idea @regexman
And in my opinion what @ElVaranCubico_YT said was correct

Below is an example, why functions for saving is hard
Example 1 (Functions):

local function getmaterial(instance)
   local stringtoreturn = tostring(instance.Material)
   return stringtoreturn
end

local table = {
  ["Material"] = getmaterial(instance)
}

Both the methods work, but a 1 line script is better than a 4 line script

Example 2 (Normal):

local table = {
 ["Material"] = tostring(instance.Material)
}

See how easy it is

I’m not telling what you explained was wrong, but I’m just suggesting you to mention an easy way

1 Like

ok i agree, ill do that

i included it later in the step 1

Ok, ive used people’s suggestions that improved my tutorial thanks to @Deadwoodx

there might be a mistake in a tutorial, please quote so if you find one

How exactly would I use this to save the player’s position? I’ve attempted it with this method but I’ve obviously done it wrong.

Here is my code:


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

game.Players.PlayerAdded:Connect(function(plr)
	
	local Character = plr.Character or plr.CharacterAdded:Wait()
	
	local Root = Character:WaitForChild("HumanoidRootPart")
	
	Position = {X = Root.CFrame.X, Y = Root.CFrame.Y, Z = Root.CFrame.Z}
	
	local RetreveData = DataStore:GetAsync("plr") or nil
	if RetreveData ~= nil then
		Root.CFrame = CFrame.new(RetreveData.X, RetreveData.Y, RetreveData.Z)
	end
end)

game.Players.PlayerRemoving:Connect(function()
	DataStore:SetAsync("plr", Position)
end)

Thanks!

you should
char:SetPrimaryPartCFrame() instead

and save the humanoidrootpart position as vector3 not cframe

char:SetPrimaryPartCFrame(CFrame.new(Vector3.new(retrieveddata.X,retrieveddata.Y,retrieeveddata.Z)))
1 Like

I’m not really good at datastore but… Aren’t you doing GetAsync(“plr”)? For what I’ve read on an article about it, you have to put the player.UserId, and you are just getting the data from the key “plr” (UserId is a key).
Try replacing "plr" with plr, actually, use plr.UserId

i think he just did it as a test. he isnt releasing it in a game i think.

1 Like

okay, ill send you my old script that works, heres the script

local position = game:GetService("DataStoreService"):GetDataStore("PlayerPositions")

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	char:WaitForChild("Humanoid")
	char:WaitForChild("HumanoidRootPart")
	-- load position if data exists
	local retrieveddata = position:GetAsync(plr.UserId) or nil
	if retrieveddata ~= nil then
		char:SetPrimaryPartCFrame(CFrame.new(Vector3.new(table.unpack(retrieveddata))))
		print("Set primary part cframe")
	end
	task.wait(2)
	while true do
		print("Saving data")
		position:SetAsync(plr.UserId,{char.HumanoidRootPart.Position.X,char.HumanoidRootPart.Position.Y,char.HumanoidRootPart.Position.Z})		
		task.wait(10)
	end
end)
1 Like

Thanks!! I’ll try it out as soon as I finish up with school!

Hello. I just tested it and for some reason it didn’t work. Sorry for the trouble.

wierd, where did you place the script? it works perfectly for me.

Wait. I’m so sorry. It’s working now. Apparently I forgot to let it save before pressing the stop button :rofl: I’m such an idiot. I’m so sorry. Should I make it so that it saves when the player leaves? I’m thinking maybe that would be better.

nah becaue what if the save thing fails

Sorry to bump in this old post, but is this possible on GUI colors, like BackgroundColor3? I’m kind of having a bad time saving colors of frames.

Yes! If you get it right, it should work. It’s just a color3 value

1 Like

Alright so I tried to work it out and it doesn’t work. It keeps turning back to the frame’s default colour
Here’s my script (might need some fixing):

local gui = game.StarterGui.TheWholePC.Frame
game:GetService("DataStoreService"):GetDataStore("Colorsy"):SetAsync("plr",{gui.BackgroundColor3.R,gui.BackgroundColor3.G,gui.BackgroundColor3.B})
local retrieveddata = game:GetService("DataStoreService"):GetDataStore("Colorsy"):GetAsync("plr")
game.StarterGui.TheWholePC.Frame = Color3.fromRGB(retrieveddata.R,retrieveddata.G,retrieveddata.B)

Funny, you forgot to type “.BackgroundColor3”

1 Like

yay!! 20 likes

I might update this tutorial if I find something new

How would you Data store the enums like keycodes? Like to have changeable key binds?