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

Why wouldn't this tool saving script work?

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)

I'm trying to save a tool called dirt and a tool called rock so that the player will get it back when the player exits the game.

Answer this question