Having problems with my DataStore code

Hello! So I have been trying to create a simplee DataStore handler for the past hour but an error just popped up that I have no idea how to solve. Any kind of help is appreciated! :smiley:

The output just warns me this: [ ServerScriptService.DataStoreHandler:41: attempt to index nil with ‘presents’] even though I have created a table variable to sort the value.

presents.Value = data.presents
cash.Value = data.cash

^ Code that causes the error.
image

And the table

local data = {		
		presents = player.leaderstats.Presents.Value;
		cash= player.Data.cash.Value;
	}

replace the second bit of code with this

local presents = player.leaderstats.Presents
local cash= player.Data.cash

I believe that will work. let me know if it doesnt try now i forgot to remove the ;s

2 Likes

It does not work because it is a table.

image

can we see your whole script please?

1 Like

Please hold on a moment. I will try to fix it, I just came up with a solution.

I edited this because I don’t want anyone to steal my code. The problem is now fixed but thanks for stopping by.

replace it with

	if success then
		presents.Value = table.find(data, Presents)
		bucks.Value = table.find(data, Bucks)

		print(player.Name.."'s data was loaded.")
	else
		print("There was an error loading "..player.Name.."'s data!")
	end

i dont know much when it comes to tables but i think that should work

1 Like

It does not show up any errors but the saving does not work.

Did you try checking in roblox client cuz datastore sometimes doesn’t work for me in studio.

1 Like

The problem is fixed now. I just rewrote the code and specifically the save part and now it works fully. Thanks though for your reply! :grinning:

1 Like