local DataStore = game:GetService("DataStoreService"):GetDataStore("StoreName") game.Players.PlayerAdded:connect(function(player) local key = "key-"..(player.userId) local folder = Instance.new("Folder",player) folder.Name = "leaderstats" local currency1 = Instance.new("IntValue",folder) currency1.Name = "Money" local save = DataStore:GetAsync(key) if save then currency1.Value = save[1] else local load = {currency1.Value} DataStore:SetAsync(key,load) end end) game.Players.PlayerRemoving:connect(function(player) local key = "key-"..(player.userId) local Folder = player:WaitForChild("leaderstats") local load = {leaderstats:FindFirstChild("Money").Value} DataStore:SetAsync(key,load) end
FORGIVE ME IF I AM ASKING MANY QUESTIONS :( I AM NEW IN THIS SCRIPTING WORLD I AM ORIGINALLY FROM THE BUILDING WORLD BUT I WANTED TO DO A NEW THING BUT I NEED SOME ADVICE FROM THE SCRIPTING WORLD AND ALSO THIS SCRIPT IS FOR DATA SAVING IF YOU CAN ANSWER THIS PLEASE SAY IF THIS IS A DATA SAVING SCRIPT CAUSE I HAVE BUILT A BANK BUT THE PLAYERS MONEY WON'T SAVE IF THEY QUIT. ALSO IF THERE'S A NY MORE PROMBLEMS PLEASE FIX THEM :(.
this is my project btw: https://www.roblox.com/games/2259153311/AY3
i think its good.
local DataStore = game:GetService("DataStoreService"):GetDataStore("StoreName") game.Players.PlayerAdded:connect(function(player) local key = "key-"..(player.userId) local folder = Instance.new("Folder",player) folder.Name = "leaderstats" local currency1 = Instance.new("IntValue",folder) currency1.Name = "Money" local save = DataStore:GetAsync(key) if save then currency1.Value = save[1] else local load = {currency1.Value} DataStore:SetAsync(key,load) end end) game.Players.PlayerRemoving:connect(function(player) local key = "key-"..(player.userId) local Folder = player:WaitForChild("leaderstats") local load = {leaderstats:FindFirstChild("Money").Value} DataStore:SetAsync(key,load) end)
Have fun.
There is no reason to accept this answer.
Here is the fixed script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("StoreName") game.Players.PlayerAdded:connect(function(player) local key = "key-"..(player.userId) local folder = Instance.new("Folder",player) folder.Name = "leaderstats" local currency1 = Instance.new("IntValue",folder) currency1.Name = "Money" local save = DataStore:GetAsync(key) if save then currency1.Value = save[1] else local load = {currency1.Value} DataStore:SetAsync(key,load) end end) game.Players.PlayerRemoving:connect(function(player) local key = "key-"..(player.userId) local Folder = player:WaitForChild("leaderstats") local load = {leaderstats:FindFirstChild("Money").Value} DataStore:SetAsync(key,load) end)
Thanks for accepting answer