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

Why isn't my datastore saving? There's no erros at all...

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

local playerDataRegular = {RobuxSpent = 0}
game.Players.PlayerAdded:Connect(function(player)
    local key = "user_"..player.UserId    
    
    local data = Instance.new("Folder")
    data.Name = "PlayerData"
    data.Parent = player
    
    local RobuxSpent = Instance.new("IntValue")
    RobuxSpent.Name = "RobuxSpent"
    RobuxSpent.Parent = data
    
    local data = DataStore:GetAsync(key)
    if data then
        RobuxSpent.Value = playerDataRegular.RobuxSpent
    end
    
    RobuxSpent.Changed:Connect(function(value)
        playerDataRegular.RobuxSpent = value
        wait()
        DataStore:SetAsync(key,playerDataRegular)
        print("saved!")
        print(playerDataRegular.RobuxSpent)
    end)
end)

So it says that it saved, but it doesn't save when I rejoin. What's the problem? I'm pretty bad at DataStores so...

4 comments

1

Line 17. Make RobuxSpent.Value = data[1]

0

Maybe change one of the variables in line 7 or 15.

0

Yeah, I got it working

0

Ugh, I just posted a solution...

1 answer

I cannot directly fix your script because I'm not familiar with your style of data saving. But you can use my style of data saving (It works perfectly).

DataStoreServiceYourDataStore:SetAsync(player.UserId.. "-AnythingYouWant", 1337) 

-- :SetAsync(The UserId of the player.. "-TheNameOfTheSavedData", TheValueOfTheSavedData)

local savedData = DataStoreServiceYourDataStore:GetAsync(player.UserId.. "-TheNameOfTheSavedDataThatYouWantToObtain")

-- :GetAsync(The UserId of the player.. "-TheNameOfTheSavedData")

You may also want to use UpdateAsync since SetAsync and GetAsync will be overwhelmed if you use too many of them. (But you can easily fix that by packing all data into a table and save the entire table. To get the values, simply unpack the table.)

You can study my data store script if you want to:

local DDS = game:GetService("DataStoreService"):GetDataStore("Arstotzkans'CommunismBank")
local remote1 = game:GetService("ReplicatedStorage").Remotes:WaitForChild("SaveEvent")
local remote2 = game:GetService("ReplicatedStorage").Remotes:WaitForChild("PayoutEvent")

game.Players.PlayerAdded:Connect(function(plr)
	local ls = Instance.new("IntValue")
	ls.Parent = plr
	ls.Name = "leaderstats"
	local rank = Instance.new("StringValue")
	rank.Parent = ls
	rank.Name = "Arstotzka"
	rank.Value = plr:GetRoleInGroup(4075766)
	local datafolder = Instance.new("Folder")
	datafolder.Parent = plr
	datafolder.Name = "DataFolder"
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 100
	money.Parent = datafolder
	local npo = Instance.new("IntValue")
	npo.Name = "NextPO"
	npo.Parent = datafolder
	npo.Value = 150
	local poa = Instance.new("IntValue")
	poa.Name = "POValue"
	poa.Parent = datafolder
	poa.Value = 100
	wait(0.5)
	local savedMoney = DDS:GetAsync(plr.UserId .. "-Money")
	if savedMoney then
		money.Value = savedMoney
	end
	if plr:IsInGroup(4075766) then
		poa.Value = 150
	end
	if plr:GetRankInGroup(4075766) == 239 then
		poa.Value = 200
	end
	if plr:GetRankInGroup(4075766) == 240 then
		poa.Value = 300
	end
	if plr:GetRankInGroup(4075766) == 241 then
		poa.Value = 250
	end
	if plr:GetRankInGroup(4075766) == 242 then
		poa.Value = 300
	end
	if plr:GetRankInGroup(4075766) == 243 then
		poa.Value = 350
	end
	if plr:GetRankInGroup(4075766) == 244 then
		poa.Value = 400
	end
	if plr:GetRankInGroup(4075766) == 245 then
		poa.Value = 450
	end
	if plr:GetRankInGroup(4075766) == 246 then
		poa.Value = 500
	end
	if plr:GetRankInGroup(4075766) == 247 then
		poa.Value = 600
	end
	if plr:GetRankInGroup(4075766) == 248 then
		poa.Value = 700
	end
	if plr:GetRankInGroup(4075766) == 249 then
		poa.Value = 800
	end
	if plr:GetRankInGroup(4075766) == 250 then
		poa.Value = 900
	end
	if plr:GetRankInGroup(4075766) == 251 then
		poa.Value = 1000
	end
	if plr:GetRankInGroup(4075766) == 253 then
		poa.Value = 1500
	end
	if plr:GetRankInGroup(4075766) == 254 then
		poa.Value = 2500
	end
	if plr:GetRankInGroup(4075766) == 255 then
		poa.Value = 5000
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local folder = plr.DataFolder
	local money = folder.Money.Value
	DDS:SetAsync(plr.UserId.. "-Money", money)
end)

remote1.OnServerEvent:Connect(function(plr, code)
	if code == "noyoudonotabuseourdatastoringsystemandwipepeopledatalol" then
	    local folder = plr.DataFolder
	    local money = folder.Money.Value
	    DDS:SetAsync(plr.UserId.. "-Money", money)
	else plr:Kick("get out of my swamp")
	end
end)

remote2.OnServerEvent:Connect(function(plr, code, cash)
	if code == "youarenevergoingtogetrichwithexploitinglolexploitequalstodatawipelolololyouwillnevercrackthisthisisthelongestcodeandimpossibletocracklololjohndoewashereandrobloxsucksgotominecraftifyouaretoopoorforaminecraftaccountgotobrickplanetxdlololimdeadokimdonenotkthxnowbye" then
		local folder = plr.DataFolder
		local money = folder.Money
		money.Value = money.Value + cash
	else plr.DataFolder.Money.Value = 0 DDS:SetAsync(plr.UserId.. "-Money", 0) wait(2.5) plr:Kick("Congrats you have been caught exploiting and your data is WIPED! >:)")
	end
end)

1 comment

0

your code check is 100% pointless

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