{SOLVED} Help with Inventory System

So, there is this weird bug in my script where I can’t store or take an item out after storing it for the 2nd time, here’s a video of it:


Here’s the Local Script:

local plrs = game:GetService("Players")

local tween = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(0.7)

local GUI = script.Parent

local plr = plrs.LocalPlayer or plrs.PlayerAdded:Wait()

local char = plr.Character or plr.CharacterAdded:Wait()

local inventory = plr:WaitForChild("Backpack")

local mouse = plr:GetMouse()

local connection
print("t")
mouse.KeyDown:Connect(function(key)
	if key == "m" then
		print("Pressed M.")
		GUI.Enabled = not GUI.Enabled
	end
end)

for _,v in pairs(GUI:GetChildren()) do
	if v:IsA("TextButton") then
		print("TextButton found: " .. v.Name)
		v.MouseEnter:Connect(function()
			local tweenTrack = tween:Create(v,tweenInfo,{["Size"] = UDim2.new(0,166,0,125)})
			tweenTrack:Play()
			v.MouseLeave:Connect(function()
				local newTweenTrack = tween:Create(v,tweenInfo,{["Size"] = UDim2.new(0, 148, 0, 108)})
				newTweenTrack:Play()
			end)
			v.MouseButton1Click:Connect(function()
				for _,tools in pairs(char:GetChildren()) do
					if tools:IsA("Tool") and tools.Parent == char then
						print("Tool equipped: Mouse clicked.")
						tools.Parent = game:GetService("ReplicatedStorage")
						v.Text = tools.Name
						v.MouseButton1Click:Connect(function()
							if tools.Parent == game:GetService("ReplicatedStorage") and v.Text == tools.Name and v.Text ~= v.Name then
								tools.Parent = inventory
								v.Text = v.Name
							end
						end)
					end
				end
			end)
		end)
	end
end

You can see, I have tried many methods of fixing this bug but this still occurs. Thank you for reading this.

Your connection to MouseButton1Click is inside of MouseEnter connection (MouseLeave is inside too), that means the more you move your mouse into the button, the more functions you will activate on click. Don’t nest your connections :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.