I’ve been stuck the past 2 days, trying to make datasave script but it does not work somehow…
Here is the code:
local DataStoreService = game:GetService("DataStoreService")
local MarketplaceService = game:GetService("MarketplaceService")
local myDataStore = DataStoreService:GetDataStore("PlayerLocker")
local RadioRemote = game:GetService("ReplicatedStorage"):FindFirstChild("Check_ItemsEquipped"):FindFirstChild("RadioBoolValue")
local RADIO_PASS_ID = 663864800
game.Players.PlayerAdded:Connect(function(Player)
local userId = Player.UserId
local FolderOwned = Instance.new("Folder")
FolderOwned.Name = "ItemsOwned"
FolderOwned.Parent = Player
local RadioOwned = Instance.new("BoolValue")
RadioOwned.Name = "RadioOwned"
RadioOwned.Parent = FolderOwned
local FolderEquipped = Instance.new("Folder")
FolderEquipped.Name = "ItemsEquipped"
FolderEquipped.Parent = Player
local RadioEquipped = Instance.new("BoolValue")
RadioEquipped.Name = "RadioEquipped"
RadioEquipped.Parent = FolderEquipped
RadioOwned.Value = MarketplaceService:UserOwnsGamePassAsync(userId, RADIO_PASS_ID)
local data
local success, errorMessage = pcall(function()
data = myDataStore:GetAsync(userId.."_RadioEquipped")
end)
if success then
RadioEquipped.Value = data
-- RadioRemote:FireClient(Player ,data)
print("Successfully loaded the data for "..Player.Name.." | UserID: "..userId)
else
print("There was an error loading the data for "..Player.Name.." | UserID: "..userId)
warn(errorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
print("PLAYER LEAVING!!!")
local userId = Player.UserId
local success, errormessage = pcall(function()
myDataStore:SetAsync(userId.."_RadioEquipped", Player.ItemsEquipped.RadioEquipped.Value)
end)
if success then
print("Data successfully saved! for "..Player.Name.." | UserID: "..userId)
else
print("There was an error saving the data for "..Player.Name.." | UserID: "..userId)
warn(errormessage)
end
end)