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

data store service isn't saving?

local DSS = game:GetService("DataStoreService")
 
local PlayerCash = DSS:GetDataStore("Tix")
 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
    	local Folder = Instance.new("Folder")
		Folder.Name = "Data"
    	Folder.Parent = Player
    	local Cash = Instance.new("IntValue")
		Cash.Name = "Tix"
    	Cash.Parent = Player.Data
    	Cash.Value = PlayerCash:GetAsync(Player.userId) or 0
 
		game.Players.PlayerRemoving:connect(function(Player)
			PlayerCash:SetAsync(Player.userId, Cash.Value)
		end)
	end)
end)

When I test out to see if it works, it doesn't save at all. If I change the intvalue, it changes. But when I stop studio to see if it worked and play it again. It sets back to zero.

5 comments

0

You're doing players removing inside of player added?

0

Am I supposed to put them in separate scripts?

0

No, just not inside of eachother.

0

So, you would take out the removing, and put it under the last end)

0

I mean it works its just that now theres an error saying "Value is not a valid member of GlobalDataStore."

1 answer

✓ Accepted answer

Do you have API services enabled?

If you already do then I don't know what's going on. However, I do have a script made by XxxLloyd061302xxX, my favorite youtuber.

local ds = game:GetService("DataStoreService"):GetDataStore("--Cash01")

game.Players.PlayerAdded:Connect(function(player)
	local key = "cash-"..player.userId
	local folder = Instance.new("Folder",player)
	folder.Name = "leaderstats" -- Must be lowercase
	local currency = Instance.new("IntValue",folder)
	currency.Name = "Money"
	currency.Value = 0
	
	local save = ds:GetAsync(key)
	if save then
		currency.Value = save
	end
	currency.Changed:Connect(function()
		ds:SetAsync(key,currency.Value)
	end)
end)

You can chose to use it or not. I just thought I might put this up here for others with the same question. Subscribe to the script maker here

Best wishes, Jail

1 comment

0

I have API services turned on. But this script works for me. Thank you!

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