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

My data store doesn't save when I load into game. Why?

Asked by
mxpvjn 75
4 years ago

I've been looking at this for an hour and can't seem to find why the datastore isn't saving. (At 0 every time I load)

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

game.Players.PlayerAdded:Connect(function(player)
    print("Called")




local key = player.UserId


--

local Data = Instance.new("Folder", player)
Data.Name = "Data"


--Data
local Level = Instance.new("IntValue", Data)
Level.Name = "Level"

local Breathing = Instance.new("IntValue", Data)
Breathing.Name = "Breathing"

local ValuesToSave = {Level.Value, Breathing.Value}


local SavedValues = DataStore:GetAsync(key)

if SavedValues then
    print("Set Levels")
    Level.Value = SavedValues[1]
    Breathing.Value = SavedValues[2]
else
    DataStore:SetAsync(key,ValuesToSave)
end





end)

game.Players.PlayerRemoving:Connect(function(player)
    local ValuesToSave = {player.Data.Level.Value, player.Breathing.Level.Value}
    DataStore:SetAsync(player.userId, ValuesToSave)
end)
0
http://idownvotedbecau.se/nodebugging/ psst, player removing programmerHere 371 — 4y
0
I just added that before it was a while true script and every 10 seconds it would save. Still wasn't working. mxpvjn 75 — 4y

Answer this question