I have made my own datastore system which should work in this method:
Player joins and the data is loaded
Data from the server is replicated to the client
Player leaves and the data on the client gets replicated to the server
Data gets saved on the server
The problem I have is that since I am not aware of any alternative to PlayerRemoving event from the client, I made a PlayerRemoving event from the server which fired a RemoteEvent to the client which should Invoke the Server through a RemoteFunction to save the data, hence the problem being that the RemoteFunction is not triggering.
The issue I think is that FireClient is not triggering.
Server Script:
--Triggering the replication of the cache from the client to the server
game.Players.PlayerRemoving:Connect(function(player)
FE.Cache2Data:FireClient(player) --The problem ???
print("this fires")
end)
--Saving the cache into the datastore.
function FE.SaveData.OnServerInvoke(player, cache)
print("not firing")
if cache then
ds:Save(player, cache)
end
end
Local Script
--Get the cache from the client and replicate it to the server
FE.Cache2Data.OnClientEvent:Connect(function()
print("this is not firing!")
FE.SaveData:InvokeServer(cache)
end)
I think that it’s because in the time that it takes to send the event to the client, the client has left the server, thus destroying the local script (that i’m assuming is in the player) that controls the remote function firing.
EDIT: Interestingly enough, when I disabled accurate play solo, everything worked as you intended it to… Not quite sure what to say now if i’m honest.
Not sure if I did it correct, but this doesn’t seem to be working
--Triggering the replication of the cache from the client to the server
game.Players.PlayerRemoving:Connect(function(player)
game:BindToClose(function()
FE.Cache2Data:FireClient(player)
wait(30)
print("this fires")
end)
end)
It stops the game from shutting down for 30 seconds allowing data to save in studio. However as stated this will make your studio crash when you click stop
You shouldn’t be doing this at all. Trusting the client with their own data that you’re saving is something that is very welcoming to exploiting. You should be considering the server’s version of their data as the authoritative definition, and then the cache on the client is used strictly for quick access aesthetics.
Again, do not trust the client with handling saved data. Use PlayerRemoving on the server and save the server version instead.
it’s a really bad idea to let the client send their save data to the server; the client can easily manipulate the data in whatever way they want
you should be keeping track of the clients save data on the server, ideally preforming sanity checks to ensure the client isn’t cheating in any way, and save that data when they leave
It’s still a good practice to let the server know about the changes you made to the data on the client at the time they were made or a while after, that way you have a lower probability of losing your data during a shutdown.