Here is my script, there's no output errors when ran, but when I save the "realms" value, or change it, the output doesn't put the "Data Saved" Print, and I have not the slightest idea as to why?
Here's the script! SERVERSCIRPT in WORKSPACE Any and all help is appreciated! Thank you!
local DataStore = game:GetService('DataStoreService')
local UserData = DataStore:GetDataStore('Data')
local Key = 'Player-'
function WhenPlayerJoin(Player)
local Leader = Instance.new('Folder')
Leader.Name = 'leaderstats'
Leader.Parent = Player
local BrickBux = Instance.new('IntValue')
BrickBux.Name = 'BrickBux'
BrickBux.Parent = Leader
local Collected = Instance.new('IntValue')
Collected.Name = "Collected"
Collected.Parent = Leader
local TotalCollected = Instance.new('IntValue')
TotalCollected.Name = "TotalCollected"
TotalCollected.Parent = Leader
local realms = Instance.new("IntValue")
realms.Name = "realms"
realms.Parent = Leader
local Data = UserData:GetAsync(Key..Player.UserId)
if Data then
BrickBux.Value = Data[1]
Collected.Value = Data[2]
TotalCollected.Value = Data[3]
realms.Value = Data[4]
else
BrickBux.Value = 0
Collected.Value = 0
TotalCollected.Value = 0
realms.Value = 0
end
for i, child in pairs(Leader:GetChildren()) do
child.Changed:connect(function()
UserData:SetAsync(Key..Player.UserId,{BrickBux.Value,Collected.Value,TotalCollected.Value,realms.Value})
print("Data Saved")
end)
end
end
function PlayerLeaving(Player)
local BrickBux = Player.leaderstats.BrickBux
local Collected = Player.leaderstats.Collected
local TotalCollected = Player.leaderstats.TotalCollected
local realms = Player.leaderstats.realms
print("The stats are there")
UserData:SetAsync(Key..Player.UserId,{BrickBux.Value,Collected.Value,TotalCollected.Value,realms.Value})
print("Data Saved")
end
game.Players.PlayerAdded:connect(WhenPlayerJoin)
game.Players.PlayerRemoving:connect(PlayerLeaving)

2 comments
Sometimes setasync doesnt work in studio because it idles out. That might be the case here. Especially since data saved isn't printing. Try testing it in game.
Also print out the value before saving just to make sure you're actually saving something