I have been trying different variations of code and viewed many hours on forums and Youtube videos on data stores and still am confused. I have done 2 datastores for cloning and level-stats and they work flawless, not sure why this is different.
I want the IronSword.Value to be saved and loaded on join and leave... The pcall prints that it's saving and loading but the value goes back to 0.
local DataStoreService = game:GetService("DataStoreService")
local Data = DataStoreService:GetDataStore("Stats")
local Store = DataStoreService:GetDataStore("StoreItems")
local function onPlayerJoin(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "Storage"
leaderstats.Parent = player
local inv = Instance.new("Folder")
inv.Name = "Inventory"
inv.Parent = leaderstats
end
-----------------------------------------------------------------------------
local weapons = game.ReplicatedStorage.Weapons
game.Players.PlayerAdded:Connect(function(plr)
local saveditems = plr.Storage.Inventory:WaitForChild("IronSword").Value
local success, err = pcall(function()
Store:GetAsync(plr.UserId.."-Values", saveditems)
end)
print(saveditems)
if success then
print("value loaded")
else
print("value failed to load")
end
while true do
local saveditems = plr.Storage.Inventory:WaitForChild("IronSword").Value
wait(10)
print(saveditems)
Data:SetAsync(plr.UserId.."-Values", saveditems)
end
end)
-----------------------------------------------------------------------------
game.Players.PlayerRemoving:Connect(function(plr)
local savedval = plr.Storage.Inventory:WaitForChild("IronSword").Value
local success, err = pcall(function()
Store:SetAsync(plr.UserId.."-Values", savedval)
end)
print(savedval)
if success then
print("value saved")
else
print("value failed to load")
warn(err)
end
end)
-----------------------------------------------------------------------------
game.Players.PlayerAdded:Connect(onPlayerJoin)
game:BindToClose(function()
wait(2)
end)
I want the IronSword.Value to be saved and loaded on join and leave... The pcall prints that it's saving and loading but the value goes back to 0.
I have been trying different variations of code and many forums and Youtube videos on data stores and still am confused.
^ this is the item and location I want to save/load the value for.

1 comment
That makes so much sense, I was not able to find anything about that on my own. Thank you man <3