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

Why isnt my custom character Data Store working?

It prints Cannot Store Array In Data Store on line 23..This is one of my first times using Data Stores so I'm a little confused as to what to do.. please help

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

game.Players.PlayerAdded:connect(function(Player)
	
	local HairValue = Player.PlayerGui:WaitForChild("ScreenGui").CustomControls.ControlScript:WaitForChild("HairValue").Value
	local HairColorValue = Player.PlayerGui:WaitForChild("ScreenGui").CustomControls.ControlScript:WaitForChild("HairColorValue").Value
	local PantsValue = Player.PlayerGui:WaitForChild("ScreenGui").CustomControls.ControlScript:WaitForChild("PantsValue").Value
	local ShirtValue = Player.PlayerGui:WaitForChild("ScreenGui").CustomControls.ControlScript:WaitForChild("ShirtValue").Value
	
	local Key = "Player-" .. Player.userId
	
	local SavedValues = DataStore:GetAsync(Key)
	
	if SavedValues then
		
		HairValue = SavedValues[1]
		HairColorValue = SavedValues[2]
		PantsValue = SavedValues[3]
		ShirtValue = SavedValues[4]
	else
		
		local ValuesToSave = {HairValue, HairColorValue, PantsValue, ShirtValue}
		SavedValues = DataStore:SetAsync(Key, ValuesToSave)
	end
end)

2 comments

0

BrickColor Values (userdata) cannot be stored in a DataStore.

0

It doesnt work when I get rid of that either.

1 answer

Not quite sure how I'd comment on your post...

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

game.Players.PlayerAdded:connect(function(Player)
	local CS  = Player.PlayerGui:WaitForChild('ScreenGui').CustomControls.ControlScript
	
	local stats = {
		CS:WaitForChild('HairValue').Value,
		CS:WaitForChild('HairColor').Value,
		CS:WaitForChild('PantsValue').Value,
		CS:WaitForChild('ShirtValue').Value
	}
    local Key = "Player-" .. Player.UserId -- This was really all I changed since userId is deprecated.

    local SavedValues = DataStore:GetAsync(Key)

    if SavedValues then
		SavedValues = stats
    else

        local ValuesToSave = stats
        SavedValues = DataStore:SetAsync(Key, ValuesToSave)
    end
end)

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