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

Datastore doesn't work and I'm not getting any errors?

So like I said in the title i'm not getting any errors, my API is enabled and I use 2 scripts one is when player leaves and other one i'm not even sure... I watched one vid on yt to do this and for that guy it works but for me it doesn't so here are the scripts I'm using:

Main:

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



game.Players.PlayerAdded:Connect(function(plr)
	local Stats = Instance.new("Folder", plr)
	Stats.Name = "Stats"
	local Cash = Instance.new("NumberValue", Stats)
	Cash.Name = "Cash"
	Cash.Value = 0
	local CashL = Instance.new("StringValue", Stats)
	CashL.Name = "CashL"
	local Damage = Instance.new("IntValue", Stats)
	Damage.Name = "Damage"
	Damage.Value = 10
	local BuxDrop = Instance.new("IntValue", Stats)
	BuxDrop.Name = "BuxDrop"
	BuxDrop.Value = 10
	local TixDrop = Instance.new("IntValue", Stats)
	TixDrop.Name = "TixDrop"
	TixDrop.Value = 20
	local BagDrop = Instance.new("IntValue", Stats)
	BagDrop.Name = "BagDrop"
	BagDrop.Value = 40
	local AutoClick = Instance.new("IntValue", Stats)
	AutoClick.Name = "AutoClick"
	AutoClick.Value = 240
	local NetWorth = Instance.new("IntValue", Stats)
	NetWorth.Name = "NetWorth"
	NetWorth.Value = 0
	local Multiplier = Instance.new("IntValue", Stats)
	Multiplier.Name = "Multiplier"
	Multiplier.Value = 0
	local UltraR = Instance.new("IntValue", Stats)
	UltraR.Name = "UltraR"
	UltraR.Value = 0
	local Square = Instance.new("IntValue", Stats)
	Square.Name = "Square"
	Square.Value = 0
	
	local key = "player-"..plr.userId
	local savedValues = DataStore:GetAsync(key)
if savedValues then
	Cash.Value = savedValues[1]
	Damage.Value = savedValues[2]
	BuxDrop.Value = savedValues[3]
	TixDrop.Value = savedValues[4]
	BagDrop.Value = savedValues[5]
	AutoClick.Value = savedValues[6]
	NetWorth.Value = savedValues[7]
	Multiplier.Value = savedValues[8]
	UltraR.Value = savedValues[9]
	Square.Value = savedValues[10]
else
	local ValuesToSave = {Cash.Value, Damage.Value, BuxDrop.Value, TixDrop.Value, BagDrop.Value, UltraR.Value, Multiplier.Value, Square.Value, AutoClick.Value}
	DataStore:SetAsync(key, ValuesToSave)
end
end)

When player leaves the game:

local DataStore = game:GetService("DataStoreService"):GetDataStore("Saves")
game.Players.PlayerRemoving:connect(function(plr)
	local s = plr.Stats
	local ValuesToSave = {s.Cash.Value, s.Damage.Value, s.BuxDrop.Value, s.TixDrop.Value, s.BagDrop.Value, s.UltraR.Value, s.Multiplier.Value, s.Square.Value, s.AutoClick.Value}
	local key = "player-"..plr.userId
	DataStore:GetAsync(key, ValuesToSave)
end)

2 comments

0

I have the same problem don't know how to fix it tho

0

RIP

1 answer

This has happened to me before, and the solution is to save the data in a cycle instead of when a player leaves. Because of how the player leaves the game, I recommend using a loop like:

while wait(10) do
	--saveData Function
end

Otherwise, values end up saving as nil for some reason.

3 comments

0

Thanks man

0

thx

0

np

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