Leader-board script doesn't work

Doesn’t work. It’s a leaderboard script.
game.Players.PlayerAdded:connect(function§
local ODS = game:GetService(“DataStoreService”):GetDataStore(p.userId)
for i = 1,#Stats do
ODS:UpdateAsync(Stats[i], function(old)
return old or 0
end)
end
local l = Instance.new(“Model”, p)
l.Name = “leaderstats”
for i = 1,#StatsNotToSave do
S = Instance.new(“NumberValue”, l)
S.Name = StatsNotToSave[i]
end
for i = 1,#Stats do
S = Instance.new(“NumberValue”, l)
S.Name = Stats[i]
if Auto_Load then
S.Value = ODS:GetAsync(Stats[i])
end
if Auto_Save then
S.Changed:connect(function()
ODS:SetAsync(Stats[i], S.Value)
end)
end
end
end)

if Save_On_Leave then
game.Players.PlayerRemoving:connect(function§
local ODS = game:GetService(“DataStoreService”):GetDataStore(p.userId)
for i = 1,#Stats do
stat = p.leaderstats:FindFirstChild(Stats[i])
if stat then
ODS:UpdateAsync(stat.Name, function(old)
return stat.Value
end)
end
end
end)
end

Any errors? Breaks? Anything? If so, they’d be extremely useful right now.

Also, could you please use codeblocks and indentation, it makes your code so much more readable.

1 Like

Adding on to what @Benified4Life said, please show us your full code. You use a Stats variable which is not defined anywhere in your provided code segment.

Also, being a little more specific than 'leaderboard script' will help immensely. What is your end goal? What is your use case?

Looking into your code, there’s already a issue:

This is not changing any datastore’s key value other than making sure they are not null. Also, they are not stored anywhere. I’m not sure what the point of this is.

This category is not for you to dump unworking code in and expect fixes. Do not create a thread saying your script doesn’t work and then post the entire thing. Apply some basic debugging to your code and if that fails to work, then supply more details such as the error you’re encountering here.

As above, please follow category guidelines when posting