My script works just fine in Studio, but it doesn't work online in a game with filtering enabled for some reason. I don't know if it's due to it being Filtering Enabled, or if I'm missing a value or two in order for this to work in-game/online.
Any help would be appreciated.
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CreditsSaveSystem")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Credits = Instance.new("IntValue",leader)
Credits.Name = "Credits"
Credits.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Credits.Value)
Credits.Changed:connect(function()
ds:SetAsync(player.UserId, Credits.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local ls = player:WaitForChild("leaderstats")
ds:SetAsync(player.UserId, ls.Credits.Value)
end)

3 comments
You need 2 script. One is leaderstats and the other is datasaves, Working datasaving - - game.Players.PlayerRemoving:connect(function(p) if p:findFirstChild("leaderstats") then p:SaveInstance("SavedStatPNum"..tostring(game.PlaceId),p.leaderstats) end end) game.Players.PlayerAdded:connect(function(p) for k = 1, 60, 0.03 do wait() if p:findFirstChild("leaderstats") and p.DataReady then break end end
Working leaderstats, - - game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue", player) stats.Name = "leaderstats" local Money = Instance.new("IntValue", stats) Money.Name = "Money" Money.Value = 10 local Points = Instance.new("IntValue", stats) Points.Name = "Points" Points.Value = 10 local maxlevel = 20 local level = Instance.new("IntValue", st
The system creates the leaderstats, and it also uses them within the same script.