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

Why wont it save this Color3Value to Datastore?

Asked by 5 years ago

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

Log in to vote
0
Answered by
yyyyyy09 246 Moderation Voter
5 years ago
Edited 5 years ago

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
0
That seemed to work, but saving it didnt.. DeathGunner132 120 — 5y
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}} yyyyyy09 246 — 5y
Ad

Answer this question