My datastore dosen't work

Okay

local GameData = DataStoreService:GetDataStore("GameData")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Money = Instance.new("IntValue")
	Money.Name = "Money"
	Money.Parent = leaderstats
	
	local Level = Instance.new("IntValue")
	Level.Name = "Level"
	Level.Parent = leaderstats
	local data
	local success,errormessage = pcall(function()
		data = GameData:GetAsync(player.UserId.."-Money","-Level")
	end)
	if success then
		Money.Value = data
		Level.Value = data
		print("Success")
	else
		print("Failed")
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success,errormessage = pcall(function()
		GameData:SetAsync(player.UserId.."-Money","-Level",player.leaderstats.Money.Value.Level.Value)
	end)
	if success then
		print("Data Has Synced")
	else
		print("Data Has Failed")
	end
end)

Still not working

Are you doing it in Roblox Studio or in the game?

Roblox Studio - why? …

Then I’m probably making a mistake in the datastore give me a sec

Do you have API Services turned on?

Yes …

Join my game cause it seems like its working for me

I joined but how can i change my values so i can see if it works

Sorry you can’t I only have access too Dev Console commands

Yoo rejoin the game I’ve added a bindtoclose function

I joined

This is needed in the datastore

1 Like

AlvinBlox made a tutorial about Datastore here

The tutorial that alvinblox made about Datastore isn’t efficient enough and the reason why I’m saying this because he didn’t teach about BindToClose function inorder too make a successful datastore you need to how too use BindToClose Function

https://www.youtube.com/watch?v=at9Yhjt572c here is a more efficient datastore tutorial that also covers BindToClose Function

1 Like

I got it to work!! textlimited