Hello, I am trying to make a script that will save data to a plr’s userId after they buy an item/boolVal (this way even if they leave the game they will still have their item) and then load it when the plr rejoins. The only issue is that when I try to load it after they join it loads alot of data that isn’t that plrs’s data. I have tried many different accounts and the same thing happens. Any ideas?
-- Save script
elseif v.Time.Value == 0 then
v.CanBid.Value = false
local Data = game:GetService("DataStoreService"):GetDataStore("ItemSaves"):GetAsync("ItemSaveData-save")
local savedItems = game:GetService("DataStoreService"):GetDataStore("ItemSaves"):GetAsync("ItemSaveData-save2")
if game.Players:FindFirstChild(v.Bidder.Value) then
local plr = game.Players:FindFirstChild(v.Bidder.Value)
local clone = Instance.new("BoolValue", plr)
clone.Parent = plr
clone.Name = v.Name
clone.Value = true
end
table.insert(savedItems, {
Name = v.Name
})
game:GetService("DataStoreService"):GetDataStore("ItemSaves"):SetAsync("ItemSaveData-save", savedItems, v.Bidder.Value.UserId)
wait(1.5)
v:Destroy()
game.ServerStorage.ItemsCount.Value -= 1
end```
```lua
-- load script
local Data = game:GetService("DataStoreService"):GetDataStore("ItemSaves"):GetAsync("ItemSaveData-save")
if Data then
-- Load all saved items
for _, itemData in pairs(Data) do
local Name = itemData.Name
--if not plr:FindFirstChild(Name) then
local clone = Instance.new("BoolValue", plr)
clone.Parent = plr
clone.Name = Name
clone.Value = true
--end
end
else
game:GetService("DataStoreService"):GetDataStore("ItemSaves"):SetAsync("ItemSaveData-save", {}, plr.UserId)
print("no data found")
end
local savedItems = game:GetService("DataStoreService"):GetDataStore("ItemSaves"):GetAsync("ItemSaveData-save")
plr.ChildRemoved:Connect(function(child)
if game.ServerStorage.AuctionItems:FindFirstChild(child.Name) then
table.remove(savedItems, 1, {
Name = child.Name
})
print("removed")
game:GetService("DataStoreService"):GetDataStore("ItemSaves"):SetAsync("ItemSaveData-save", savedItems, plr.UserId)
end
end)```
