MODULE
local Module = {Data = {}}
local DataStoreService = game:GetService("DataStoreService");
local KeyPrefix = "data_user#";
local DataStore = DataStoreService:GetDataStore("TestData_v.15");
local DataTemplate = {
Money = 300;
Level = 1;
};
local function GetKey(id)
return KeyPrefix .. id;
end;
Module.InitializeData = function(plr)
local Key = GetKey(plr.UserId);
Module.Data[plr] = DataStore:GetAsync(Key) or DataTemplate;
end;
Module.ConcludeData = function(plr)
local Key = GetKey(plr.UserId);
local Data = Module.Data[plr];
if Data and Data ~= nil then
DataStore:SetAsync(Key, Data);
Data = nil;
end;
end;
return Module;
SCRIPT
local DataModule = require(script.Parent:WaitForChild("DataModule"));
game.Players.PlayerAdded:Connect(function(Player)
DataModule.InitializeData(Player);
end);
game.Players.PlayerRemoving:Connect(function(Player)
DataModule.ConcludeData(Player);
end);
This is what I'm having trouble with. When in game and the data is changed, it works n all, but when i leave and rejoin, i have the default data.. It's tough because this used to be my method and worked like 100% of the time, and it just recently stopped.. Roblox did an update on studio not too long ago, could it be that??

8 comments
hey wht is there ";" at the end of each line?
idk, i kinda just picked it up and its a habit at this point
it doesn't affect the script though, those have always been there
Try to do a BindToClose waiting for the data save.
I tried that.. Roblox must've done something that messed with it because all my other datastores (in different games) aren't saving either...
Can you show the script complete?
Edited, should show it all
After testing, I've found that it pretty much works in-game, but studio is a flop when it comes to working w/ it. (API thingy enabled in studio also so idrk what it is) It's gonna be a little annoying to have to test a lot in-game but oh well, at least it works! Thank y'all for the help!