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

My data store wont work, no errors come up and I dont know why?

Asked by 5 years ago

local DS = game:GetService('DataStoreService')

local MSD = DS:GetDataStore('MSD')

game.Players.PlayerAdded:Connect(function(plr)

local stats = Instance.new("BoolValue",plr)

stats.Name = "leaderstats"

local Cash = Instance.new("IntValue",stats)

Cash.Name = "Cash"

Cash.Value = 1020

local cps = Instance.new('IntValue', stats)

cps.Name = "CPS"

local data

local data2

local success, errormessage = pcall(function()

data = MSD:GetAsync(plr.UserId..'-Cash')

data2 = MSD:GetAsync(plr.UserId..'-CPS')

end)

if success then

Cash.Value = data

cps.Value = data2

end

end)

game.Players.PlayerRemoving:Connect(function(plr)

local success, errormessage = pcall(function()

MSD:SetAsync(plr.UserId..'-Cash', plr.leaderstats.Cash.Value..'-CPS', plr.leaderstats.CPS.Value)

end)

if success then

print('Data successfully saved')

else

print('There was an error saving data')

warn(errormessage)

end

end)

1 answer

Log in to vote
0
Answered by 5 years ago
local DSService = game:GetService('DataStoreService'):GetDataStore('') --Change this name to a random name or it will not workgame.
Players.PlayerAdded:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue', plr)
local savevalue = Instance.new('IntValue')
leaderstats.Name = 'leaderstats'
savevalue.Parent = leaderstats
savevalue.Name = 'Points'
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Points.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
0
this is a data store I have created, I hope this helps cooldrewbie 94 — 5y
0
That doesnt work either for some reason XxepicfaceXx313 0 — 5y
Ad

Answer this question