local DS = game:GetService("DataStoreService"):GetDataStore("Data")
game.Players.PlayerAdded:Connect(function(plr)
local l = Instance.new("Folder")
l.Name = "leaderstats"
l.Parent = plr
local v = Instance.new("IntValue")
v.Name = "Energy"
v.Parent = l
local file = DS:GetAsync(plr.UserId)
if file then
v.Value = file[1]
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:GetAsync(plr.UserId,{plr.leaderstats.Points.Value})
end)
COMMUNITY QUESTION
So I Got This Script From Youtube and it wont work. I’m guessing its outdated?
1 answer
This is your problem:
At line 21, you are calling :GetAsync() instead of :SetAsync().
here is the fixed script:
local DS = game:GetService("DataStoreService"):GetDataStore("Data")
game.Players.PlayerAdded:Connect(function(plr)
local l = Instance.new("Folder")
l.Name = "leaderstats"
l.Parent = plr
local v = Instance.new("IntValue")
v.Name = "Energy"
v.Parent = l
local file = DS:GetAsync(plr.UserId)
if file then
v.Value = file[1]
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
DS:SetAsync(plr.UserId,{plr.leaderstats.Points.Value})
end)
Note that sometimes roblox doesnt really save data is studio, but it does in the actual game.
This discussion is preserved as it was. New answers, comments, and votes are closed.

13 comments
what have you done the fix the script, waht isnt working, did you try in studio or in game?
I cant find a error for it. I am also new to scripting
did you test in studio?
did you test in studio?
did you test in studio?
did you test in studio?
?
sorry lag
sorry lag
sorry lag
sorry lag
sorry lag
sorry lag