I am trying to make it so that when the player places an object, there will be an instance called SaveRequest, its parent is in
game.Players.LocalPlayer.HiddenStats.ItemPos
and I am trying to save the value and load it when the player joins back in the game but it is LITERALLY IMPOSSIBLE, Someone, come on, please help me D:
local DataStore = game:GetService("DataStoreService"):GetDataStore("ForSnapToGrid") _G["Inventory"] = {} game.Players.PlayerAdded:connect(function(player) print("Found player") local stats = Instance.new("Folder", player) stats.Name = "HiddenStats" ObjectPos = Instance.new("Folder", stats) ObjectPos.Name = "ItemPos" local Gold = Instance.new("IntValue", stats) Gold.Name = "Item Data Store Name" Gold.Value = 0 local key = "player-"..player.userId if game:GetService("RunService"):IsStudio() then -- else savedValues = DataStore:GetAsync(_G["Inventory"], key) print(_G["Inventory"].Value) print("Finding saved items") if savedValues then print("Getting items") --Save format: {points, coins} Gold.Value = savedValues[1] a = 1 for _, v in pairs(_G["Inventory"]) do local newVector3Value = Instance.new("Vector3Value", ObjectPos) newVector3Value = Vector3.new(v) end print("Fetched items") else print("Making storage") local valuesToSave = {Gold.Value, _G["Inventory"]} DataStore:SetAsync(key, valuesToSave) end end end) game.Players.PlayerRemoving:connect(function(player) for _, v in pairs(ObjectPos:GetChildren()) do v.Value = Vector3.new(savedValues[a]) -- Reminder: Since the folder gets emptied when the player leaves, this won't work! a = a + 1 print(a) table.insert(_G["Inventory"], v.Value) end local key = "player-"..player.userId for _, v in pairs(_G["Inventory"]) do print(Vector3.new(v)) end DataStore:SetAsync(_G["Inventory"], key) end)
Attempted script ^
And there is no errors :(