Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do you save a tool in your inventory to a value?

Asked by
thortol 22
8 years ago
local DataStore = game:GetService("DataStoreService"):GetDataStore("CheckTools")
  game.Players.PlayerAdded:connect(function(player)

local ToolSaveFolder = Instance.new("Folder", player)   
ToolSaveFolder.Name = "ToolSaveFolder"

local tool1 = Instance.new("IntValue", ToolSaveFolder)
tool1.Name = "Dirt"

local tool2 = Instance.new("IntValue", ToolSaveFolder)
tool2.Name = "Rock"
wait(5)
if player.ToolSaveFolder.Dirt.Value >= 1 then
    game.ServerStorage.Tools.Dirt:Clone().Parent = player.Backpack
    game.ServerStorage.Tools.Dirt:Clone().Parent = player.StarterGear
end
if player.ToolSaveFolder.Rock.Value >= 1 then
    game.ServerStorage.Tools.Rock:Clone().Parent = player.Backpack
    game.ServerStorage.Tools.Rock:Clone().Parent = player.StarterGear
end

local key = "user-"..player.userId  

local savedCheck = DataStore:GetAsync(key)  

if savedCheck then
    tool1.Value = savedCheck[1]
    tool2.Value = savedCheck[2]
else
    local SavedValues = {tool2.Value, tool1.Value}
    DataStore:SetAsync(key, SavedValues)
end     
 end)
 local DataStore = game:GetService("DataStoreService"):GetDataStore("CheckTools")

    game.Players.PlayerRemoving:connect(function(player)

local key = "player-"..player.userId    
local savedCheck = {player.ToolSaveFolder.Dirt.Value, player.ToolSaveFolder.Rock.Value} 
DataStore:SetAsync(key, savedCheck)
end)    

This script is suppose to save tools in your inventory. For example there is a tool called dirt in your inventory. So the code will save the value 1 into the value, and when the player logs in again, it will load a Dirt as the value is 1. However, the code doesn't seem to save the value 1.

Answer this question