03:37:34.495 Script Testing @ 22 May 2023 03:37 auto-recovery file was created - Studio
03:37:36.034 ServerScriptService.PointsSystem:32: Expected ‘)’ (to close ‘(’ at column 6), got ‘to’ - Studio - PointsSystem:32
03:37:42.971 Infinite yield possible on ‘Players.JackyssWrld:WaitForChild(“leaderstats”)’ - Studio
03:37:42.971 Stack Begin - Studio
03:37:42.971 Script ‘Players.JackyssWrld.PlayerGui.TicketShop.MainFrame.Item1.LocalScript’, Line 10 - Studio - LocalScript:10
03:37:42.971 Stack End - Studio
03:37:42.971 Infinite yield possible on ‘Players.JackyssWrld:WaitForChild(“leaderstats”)’ - Studio
03:37:42.972 Stack Begin - Studio
03:37:42.972 Script ‘Players.JackyssWrld.PlayerGui.TicketShop.MainFrame.Item1.LocalScript’, Line 10 - Studio - LocalScript:10
03:37:42.972 Stack End - Studio
03:37:42.972 Infinite yield possible on ‘Players.JackyssWrld:WaitForChild(“leaderstats”)’ - Studio
03:37:42.972 Stack Begin - Studio
03:37:42.972 Script ‘Players.JackyssWrld.PlayerGui.TicketShop.MainFrame.Item1.LocalScript’, Line 10 - Studio - LocalScript:10
03:37:42.972 Stack End - Studio
03:37:42.972 Infinite yield possible on ‘Players.JackyssWrld:WaitForChild(“leaderstats”)’ - Studio
03:37:42.973 Stack Begin - Studio
03:37:42.973 Script ‘Players.JackyssWrld.PlayerGui.TicketShop.MainFrame.Item1.LocalScript’, Line 10 - Studio - LocalScript:10
03:37:42.973 Stack End - Studio
03:37:42.973 Infinite yield possible on ‘Players.JackyssWrld:WaitForChild(“leaderstats”)’ - Studio
03:37:42.973 Stack Begin - Studio
03:37:42.973 Script ‘Players.JackyssWrld.PlayerGui.TicketShop.MainFrame.Item1.LocalScript’, Line 10 - Studio - LocalScript:10
I tested it and works as intended on my side. I joined, I got 50, I changed that to 80, got the print of 80, I rejoined and I got 80 as expected
Im using this script:
local DataStoreService = game:GetService("DataStoreService")
local pointsStore = DataStoreService:GetDataStore("pointsStore")
game.Players.PlayerAdded:Connect(function(Player)
local success, SavedPoints = pcall(function()
return pointsStore:GetAsync(Player.UserId)
end)
local Leaderstats = Player:FindFirstChild("leaderstats") or Instance.new("Folder", Player)
Leaderstats.Name = "leaderstats"
local PointsValue = Leaderstats:FindFirstChild("Points") or Instance.new("IntValue", Leaderstats)
PointsValue.Name = "Points"
if success then
if SavedPoints then
warn("player has data")
PointsValue.Value = SavedPoints
else
warn("player is new")
PointsValue.Value = 50
end
else
warn("DSS failed")
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local stuffToSave = Player.leaderstats.Points.Value
warn("stuff to save:", stuffToSave)
local success, err = pcall(function()
return pointsStore:SetAsync(Player.UserId, stuffToSave)
end)
if success then
warn("saved succsess")
else
warn("Saving DSS failed", err)
end
end)
Maybe your studio is closing fast the testPlay and not having enough time to save the datastore. Try this code:
local DataStoreService = game:GetService("DataStoreService")
local pointsStore = DataStoreService:GetDataStore("pointsStore")
game.Players.PlayerAdded:Connect(function(Player)
local success, SavedPoints = pcall(function()
return pointsStore:GetAsync(Player.UserId)
end)
local Leaderstats = Player:FindFirstChild("leaderstats") or Instance.new("Folder", Player)
Leaderstats.Name = "leaderstats"
local PointsValue = Leaderstats:FindFirstChild("Points") or Instance.new("IntValue", Leaderstats)
PointsValue.Name = "Points"
if success then
if SavedPoints then
warn("players data in DS:", SavedPoints)
PointsValue.Value = SavedPoints
else
warn("player is new")
PointsValue.Value = 50
end
else
warn("DSS failed")
end
end)
local function Save(Player)
local stuffToSave = Player.leaderstats.Points.Value
warn("stuff to save:", stuffToSave)
local success, err = pcall(function()
return pointsStore:SetAsync(Player.UserId, stuffToSave)
end)
if success then
warn("saved success")
else
warn("Saving DSS failed", err)
end
end
game.Players.PlayerRemoving:Connect(function(Player)
Save(Player)
end)
game:BindToClose(function()
warn("waiting 3secs before closing")
for _, p in pairs(game.Players:GetPlayers()) do
Save(p)
end
task.wait(3)
end)