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

My datastore script isn't working, what did I do wrong and how should I do it right?

What's wrong with my datastore script? I really have no idea :( Can someone please explain?

local DataStoreService = game:GetService("DataStoreService")

local DataStoring = DataStoreService:GetDataStore("DataStoring")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("IntValue", player)
	leaderstats.Name = 'leaderstats'
	
	local DRcoins = Instance.new("IntValue", leaderstats)
	DRcoins.Name = 'DRcoins'
	DRcoins.Value = 0
	print("leaderstats generated")
	
	local data
	local success, errormessage = pcall(function()
		data = DataStoring:GetAsync(player.UserId.. "-DRcoins")
	end)
	
	if success == true then
		DRcoins.Value = data
	else
		print("There was an error in retrieving your data")
		warn(errormessage)
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		DataStoring:SetAsync(player.UserId.. "-DRcoins", player.leaderstats.DRcoins.Value)
	end)	
	if success == true then
		print("Playerdata succesfully saved")
	else
		print("Something went wrong with saving data")
		warn(errormessage)
	end
end)



the script^

5 comments

0

Just to clarify, you are testing this in-game and not in studio with API services enabled?

0

I published and tested using ROBLOX player, do you see any mistakes that I made in the script or so?

0

Do you have API services enabled in settings? - before i answer that (It's a common error)

0

Yes I have API services enabled for the game

0

I found out why.

1 answer

✓ Accepted answer

I found the error:

06	    local leaderstats = Instance.new("IntValue", player)

needs to be a Folder

06	    local leaderstats = Instance.new("Folder", player)

When using AlvinBlox as a source remember:

Look closely and how he explains things : Don't rush ahead.

4 comments

0

Okay I'll try if it will work now :)

0

Alright.

0

It works! :D Thank you very much :)

0

No problem.

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