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

Help me when i use a tool that tool was removed?

Asked by 5 years ago
Edited 5 years ago
local itemsTable = 
game.Players.LocalPlayer.Inventory:GetChildren() -- or   folder:GetChildren()
local player = game.Players.LocalPlayer
local Enabled = false
game.StarterGui:SetCoreGuiEnabled('Backpack',false)
function UpdateInventory()
if Enabled == false then
Enabled = true
script.Parent.Backpack:ClearAllChildren()
for i,v in pairs(player.Inventory:GetChildren()) do
local Obj1 = Instance.new('TextButton',script.Parent.Backpack)
Obj1.Size = UDim2.new(1,0,0.05,0)
Obj1.BackgroundTransparency = 1
Obj1.TextScaled = true
Obj1.Text = v.Name
Obj1.Font = 'Cartoon'
Obj1.TextColor3 = Color3.new(0,0,0)
Obj1.MouseButton1Down:connect(function()
player.Character.Humanoid:UnequipTools()
player.Character.Humanoid:EquipTool(v)
end)
end
else
Enabled = false
end
end  
 script.Parent.Parent.Parent.OpenInventory.MouseButton1Down:connect(function()
UpdateInventory()
end) 
player.Backpack.Changed:connect(function()
if Enabled == false then Enabled = true UpdateInventory() end
if Enabled == true then Enabled = false UpdateInventory() end
end)

help me i when i use a tool, tool will insta remove

1 answer

Log in to vote
0
Answered by
blowup999 659 Moderation Voter
5 years ago

The main problem I see with the code is if Enabled == false then Enabled = true UpdateInventory() end

When the Backpack changes at all it runs this function Enabled starts false so when it's false you immediately set it to true and run UpdateInventory()

However, in UpdateInventory you then immediately run as if enabled == true and the only thing it does is set Enabled = false.

This makes it so that your script never actually runs Enabled == false in the UpdateInventory function

0
wont work its always remove my tools from inventory dark_nineret -25 — 5y
Ad

Answer this question