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

Why wont it save this Color3Value to Datastore?

I've tried alot and cant seem to get it to save. At line 9 it also says argument 1 missing or nil I'd also like to know why. The main point of what I'm trying to do is save a Table, so focus on that.

DS = game:GetService("DataStoreService"):GetDataStore('gearvaleuz')
http = game:GetService('HttpService')

--Loading Data
local function PlrAdd(player)

local GearDataLoad = game.ReplicatedStorage:WaitForChild('profile'):WaitForChild(player.Name):WaitForChild('GearData')

LD = http:JSONDecode(DS:GetAsync('GearColor'))

GearColorLoad = {
	Color1 = Color3.fromRGB(LD['GClr'][1],LD['GClr'][2],LD['GClr'][3])
}
local Gear = workspace:WaitForChild(player.Name..'s Gear')
Gear:WaitForChild('GearColorValue').Value = GearColorLoad[1]

end

--Saving Data

game.Players.PlayerRemoving:connect(function(plr)

local GearDataSave = game.ReplicatedStorage:WaitForChild('profile'):WaitForChild(plr.Name):WaitForChild('GearData')

GearColorSave= httpJSONEncode({
	['GClr'] = {
		GearDataSave.GearColor.Value.r,
		GearDataSave.GearColor.Value.g,
		GearDataSave.GearColor.Value.b	
} 
})

DS:SetAsync('GearColor',GearColorSave)
end)

game.Players.PlayerAdded:connect(PlrAdd)

Thank you for taking your time to read this.

1 answer

You're trying to take data out of an empty datastore, that's why it's nil, you save the data afterwords. So when a player enters the game they have no "GearColor" data, and when you try to retrieve it, it's "nil", so the error is correct, you're trying to Decode absolutely nothing.

instead try this


local function PlrAdd(player)

	local GearDataLoad = game.ReplicatedStorage:WaitForChild('profile'):WaitForChild(player.Name):WaitForChild('GearData')
	
	if DS:GetAsync('GearColor') ~= nil then

		LD = http:JSONDecode(DS:GetAsync('GearColor'))

		GearColorLoad = {
			Color1 = Color3.fromRGB(LD['GClr'][1],LD['GClr'][2],LD['GClr'][3])
		}

		local Gear = workspace:WaitForChild(player.Name..'s Gear') 

		Gear:WaitForChild('GearColorValue').Value = GearColorLoad[1]
	end
end

3 comments

0

That seemed to work, but saving it didnt..

0

This should work instead of all the httpJSONEncoding stuff, It should save in this case, local GearColorSave = {["GClr"] = {script.Parent.Value.Value.r,script.Parent.Value.Value.g,script.Parent.Value.Value.b}}

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