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)
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.
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.
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.
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.
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.
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.
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