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

Why isnt my custom character Data Store working?

Asked by 7 years ago
Edited 7 years ago

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)
0
BrickColor Values (userdata) cannot be stored in a DataStore. TheHospitalDev 1134 — 7y
0
It doesnt work when I get rid of that either. SHDrivingMeNuts 299 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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)

Ad

Answer this question