Hello, so i got this script right here that is suppost to save my shirts/pants that i bought in-game using in-game currency so i dont have to buy them again after leaving/dying.
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local shirtId = character:WaitForChild("Shirt").ShirtTemplate
local pantsId = character:WaitForChild("Pants").PantsTemplate
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId)
end)
if success then
shirtId = data[1]
pantsId = data[2]
else
print('idk something wont work lol')
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local shirtId = character:WaitForChild("Shirt").ShirtTemplate
local pantsId = character:WaitForChild("Pants").PantsTemplate
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId, {shirtId, pantsId})
end)
if success then
print ("Player Data successfully saved")
else
print ("Error saving data")
warn(errormessage)
end
end)
the thing is that it doesn’t work, and there are no errors. can some1 help.