I have a problem saving tools with dataStore. The dataStore works fine on its own, only I just made a new item slots GUI, and equipping the item no longer saves for some reason
GUI slots:
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.2)
local player = game.Players.LocalPlayer
local character = player.Character
local Handler = script.Parent.Parent.Mapa.ViewSelection.Inventario.Handler
local selected = Handler.Selected
local equipped = Handler.Equipped
local location = Handler.Location
local EnabledEquipTool = script.Parent:WaitForChild("EnabledEquipTools")
local Main = script.Parent
local Debounce = false
local KeeyOne = false
local KeeyTwo = false
local KeeyThree = false
local KeeyFour = false
local KeeyFive = false
UserInputService.InputBegan:Connect(function(key)
if EnabledEquipTool.Value == false then
if not Debounce then
Debounce = true
if key.KeyCode == Enum.KeyCode.One then
if Main.Slot1.Item.Value == nil then
else
if KeeyOne == false then
if location.Value == player.Backpack then
TweenService:Create(Main.Slot1, tweenInfo, {ImageColor3 = Color3.fromRGB(66, 66, 66)}):Play()
character.Humanoid:EquipTool(Main.Slot1.Item.Value)
equipped.Value = Main.Slot1.Item.Value
KeeyOne = true
end
else
TweenService:Create(Main.Slot1, tweenInfo, {ImageColor3 = Color3.fromRGB(0, 0, 0)}):Play()
character.Humanoid:UnequipTools()
equipped.Value = nil
KeeyOne = false
end
end
end
wait(0.2)
Debounce = false
end
end
end)
DataStore:
local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolDataPlayer")
local toolsFolder = game.ServerStorage.ToolsFolder
game.Players.PlayerAdded:Connect(function(plr)
local toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools") or {}
for i, toolSaved in pairs(toolsSaved) do
if toolsFolder:FindFirstChild(toolSaved) then
toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear
end
end
plr.CharacterRemoving:Connect(function(char)
char.Humanoid:UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local toolsOwned = {}
for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do
table.insert(toolsOwned, toolInBackpack.Name)
end
local success, errormsg = pcall(function()
toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
end)
if errormsg then warn(errormsg) end
end)