My destination is creating a data store for a value named Skoupes. However, while it works in the Studio, and not exactly as expected because it doesn’t save at certain times it doesn’t even save in the Roblox Player .
I have tried to look up for any errors in the output, but it seemed like it printed as expected. So I believe that I didn’t script it like I was aiming for. Since I am not familiar with datastores and it’s my weak side I have decided to look up for any help in the devforum. Can someone help me? I would appreciate it.
local DataStoreService = game:GetService("DataStoreService")
local MyData = DataStoreService:GetDataStore("Skoypes")
game.Players.PlayerAdded:Connect(function(plr)
local skoypes = Instance.new("NumberValue")
skoypes.Parent = plr
skoypes.Name = "Skoypes"
local success, errormsg = pcall(function()
local data = MyData:GetAsync(plr.UserId)
if data then
skoypes.Value = data
print("good")
else
print("no data to be stored")
end
end)
if errormsg then
warn(errormsg)
end
if skoypes.Value > 0 then
plr.Character.HumanoidRootPart.CFrame = game.Workspace.SkoupesFile.CsSpawn.CFrame
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormsg = pcall(function()
MyData:SetAsync(plr.UserId, plr.Skoypes.Value)
end)
if success then
print("Good while saving the data")
else
warn(errormsg)
end
end)
If you truly care about persistent data which is reliable, you’re better off just using ProfileService. With automatic backups and versioning, you avoid mistakes like inserting non-primitives and corrupting data.