I want to be able to have the players only obtain this orb once, but when i run this code and try to have it save it errors out
local DataStoreService = game:GetService("DataStoreService") local orb1datastore = DataStoreService:GetDataStore("Orb1DataStore") game.Players.PlayerAdded:Connect(function(player) local orb1value = Instance.new("IntValue") orb1value.Name = "orb1" orb1value.Parent = player local data local success, errormessage pcall(function() data = orb1datastore:GetAsync(player.UserId.."orb1") end) if success then orb1value.Value = data else print("There was an error with getting your orb1 data") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage pcall(function() orb1datastore:SetASync(player.UserId.."orb1",player.orb1.Value) end) if success then print("Orb1 data successfully saved") else print("There was an error while saving orb1 data") warn(errormessage) end end)
I believe this will work:
local DataStoreService = game:GetService("DataStoreService") local orb1datastore = DataStoreService:GetDataStore("Orb1DataStore") game.Players.PlayerAdded:Connect(function(player) local orb1value = Instance.new("IntValue") orb1value.Name = "orb1" orb1value.Parent = player local data local success, errormessage pcall(function() data = orb1datastore:GetAsync(player.UserId.."orb1") end) if success then orb1value.Value = data else print("There was an error with getting your orb1 data") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage pcall(function() if player:FindFirstChild("orb1") then else print("Ok your values are noobs") return end orb1datastore:SetASync(tostring(player.UserId).."orb1",player:FindFirstChild("orb1").Value) end) if success then print("Orb1 data successfully saved") else print("There was an error while saving orb1 data") warn(errormessage) end end)