Help with this Non-FE Datastore Script

Hello everyone,

I’m having some issues with my Money Datastore script not saving the players money at all, as when they rejoin - the money resets to £0, this happened ever since ROBLOX forced FE, so I’m not sure if the script is compatible with FE.

I’d appreciate any support at all, I have looked on the Wiki to no avail. Thanks in Advance.

local DataStore=game:GetService("DataStoreService")

game.Players.PlayerAdded:connect(function(plr)
	local values=Instance.new("Folder",plr)
			values.Name="Values"
	local money=Instance.new("IntValue",values)
			money.Name="GBP"
	local DD40=Instance.new("BoolValue",values)
			DD40.Name="DD40"
	local DJ41=Instance.new("BoolValue",values)
			DJ41.Name="DJ41"
	local DJ28=Instance.new("BoolValue",values)
			DJ28.Name="DJ28"
		money.Value=DataStore:GetDataStore("MoneySave"):GetAsync(plr.UserId) or 0
			DataStore:GetDataStore("MoneySave"):SetAsync(plr.UserId, money.Value)
			money.Changed:connect(function()
			DataStore:GetDataStore("MoneySave"):SetAsync(plr.UserId,money.Value)
			end)
		DD40.Value=DataStore:GetDataStore("DD40"):GetAsync(plr.UserId) or false
			DataStore:GetDataStore("DD40"):SetAsync(plr.UserId, DD40.Value)
			DD40.Changed:connect(function()
			DataStore:GetDataStore("DD40"):SetAsync(plr.UserId, DD40.Value)	
			end)
		DJ41.Value=DataStore:GetDataStore("DJ41"):GetAsync(plr.UserId) or false
			DataStore:GetDataStore("DJ41"):SetAsync(plr.UserId, DJ41.Value)
			DJ41.Changed:connect(function()
			DataStore:GetDataStore("DJ41"):SetAsync(plr.UserId, DJ41.Value)	
			end)
		DJ28.Value=DataStore:GetDataStore("DJ28"):GetAsync(plr.UserId) or false
			DataStore:GetDataStore("DJ28"):SetAsync(plr.UserId, DJ28.Value)
			DJ28.Changed:connect(function()
			DataStore:GetDataStore("DJ28"):SetAsync(plr.UserId, DJ28.Value)	
			end)
end)


game.Players.PlayerRemoving:connect(function(plr)
	DataStore:GetDataStore("MoneySave"):SetAsync(plr.UserId, plr.Values.GBP.Value)
	DataStore:GetDataStore("DD40"):SetAsync(plr.UserId, plr.Values.DD40.Value)	
	DataStore:GetDataStore("DJ41"):SetAsync(plr.UserId, plr.Values.DJ41.Value)	
	DataStore:GetDataStore("DJ28"):SetAsync(plr.UserId, plr.Values.DJ28.Value)
end)
1 Like

I just tested your script and ran into no issues at all - are you sure you’re setting the values from the server, and not the client? Changing values on the client will not replicate to the server unless you do it manually.

3 Likes

I think they could be other parts of the MoneySystem that aren’t FE compatible if the data store script is fine, is they any chance if I send you a place file with all scripts related to the money system, do you think you could tell me which script is going wrong? As I’m unfortunately not the best scripter. :confused:

Jake :slight_smile:

Any localscript trying to edit one of those values will only show the changes on that player’s screen, not for the server, so the player(client) could have 100 GBP on their screen, but the server wouldn’t see any changes, and when they leave, the server saves that unchanged value, you might want to look into https://www.robloxdev.com/articles/Remote-Functions-and-Events and https://www.robloxdev.com/articles/Roblox-Client-Server-Model to see how to make your localscripts FE compatible

2 Likes

While this may work I wouldn’t recommend using it. You shouldn’t need to save everytime the value changes and don’t handle errors at all currently. There’s a pretty good example on the DevHub here

Also, as Class stated, your issue is with FE and how it handles replication. Player stats should be handled on server, not the client, using secure Remote Events/Funcitons with proper sanity checks when an item is purchased from a store etc. Never trust the client; validate everything it tells you.

2 Likes

There isn’t an issue with the script (i.e nothing here needs to be replicated, it is all handled on the server) - he was setting the values from the client’s end due to a lack of understanding of client and server disconnect.

OP, if you want an improved data system, I highly recommend DataStore2 by @Kampfkarren.

3 Likes

I’d use one datastore then put all the values in one table then use arrays, I’d also wouldn’t save the values for each time it changes, you should also use UpdateAsync instead of SetAsync. I’m not an expert on Datastores but I’m just trying to help you out, I’ve done this in the past and it seemed to work. Hopefully, this information can help ya. :slight_smile:

1 Like

As what @SummerEquinox said, it replicates to the whole server. I wouldn’t trust the client to handle anything with the leaderstats.

1 Like

Thats what I was thinking too. @SummerEquinox is very smart at this point in time and like @SummerEquinox is correct. I wouldn’t trust the client to handle anything with leaderstats either man, @SummerEquinox is right.

2 Likes

Yep, same here. It’s just a risk I don’t want to take.

2 Likes

Yeah, I understand that the script works - I’m saying he shouldn’t use it anyway. Pointlessly getting the store every time, no pcall, no redundancy and wasted requests. Dataloss is inevitable

1 Like

Yup - though given it seems to be a fairly basic system I think lack of data caching is to be expected.

1 Like

Thank you everyone for your help.

No problem, man. Feel free to post another topic if you need any help.

1 Like