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

How to create an autosave to save player size?

Asked by 6 years ago

Currently what this script is supposed to do is save the characters BodyWidthScale, BodyDepthScale, etc. when they leave, but that isn't working. But my actual goal for this script is to autosave these values periodically and also load when the player joins the game or resets. Any help would be appreciated!

local DataStore=game.GetService("DataStoreService"):GetDataStore("SizeSave")
game.Players.PlayerAdded:connect(function(player)
    local key = "key-"..player.userId
    local Humanoid = player.Character:WaitForChild("Humanoid")
    local Stat = Humanoid:GetChildren()
    local BHS = Humanoid.BodyHeightScale
    local BWS = Humanoid.BodyWidthScale
    local BDS = Humanoid.BodyDepthScale
    local HS = Humanoid.HeadScale
    wait(0.5)

    local save = DataStore:GetAsync(key)    
    if save then

        BHS.Value = save[1]
        BWS.Value = save[2]
        BDS.Value = save[3]
        HS.Value = save[4]
    else
        local load = {BHS.Value}
        DataStore:SetAsync(key,load)
        local load1 = {BWS.Value}
        DataStore:SetAsync(key,load1)
        local load2 = {BDS.Value}
        DataStore:SetAsync(key,load2)
        local load3 = {HS.Value}
        DataStore:SetAsync(key,load3)
    print("Data Values Saved!")
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    local key = "key-"..player.userId
    local load = {player.Character.Humanoid:FindFirstChild("BodyHeightScale").Value}
    DataStore.SetAsync(key.load)
    local load1 = {player.Character.Humanoid:FindFirstChild("BodyWidthScale").Value}
    DataStore.SetAsync(key.load1)
    local load2 = {player.Character.Humanoid:FindFirstChild("BodyDepthScale").Value}
    DataStore.SetAsync(key.load2)
    local load3 = {player.Character.Humanoid:FindFirstChild("HeadScale").Value}
    DataStore.SetAsync(key.load3)
    print("Data Values Loaded!")
end)

1 answer

Log in to vote
0
Answered by 6 years ago

Easy, all you do is use a Datastore. And the values should automatically save when being reset.

Ad

Answer this question