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.

1 answer

Log in to vote
0
Answered by
Scootakip 299 Moderation Voter
8 years ago

I'd suggest that when a player joins, have DataStore give them a value of IfThisWeapon. It should be a BoolValue, if the BoolValue is set tot true, it means they have the weapon, if it's set to false, they don't have the weapon.

if IfThisWeapon == true then
    weapon = game.ReplicatedStorage.Weapon:Clone()
    weapon.Parent = player
    else
    print("Player does not have this weapon/tool")
end

Obviously that script is unfinished and such, but you probably get the idea. If you need any help comment and I'll try to help you.

Summery: Use a Bool Value to show if a player has a certain weapon or not, as DataStore can't store tools

0
How do you let it check whether the player has the tool? thortol 22 — 8y
Ad

Answer this question