[SOLVED] Weird bug happens when storing an item

This weird glitch happens when I store an item in a slot; I can’t really explain the glitch so here’s a video of it:


Here’s the 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

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") 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") then
								tools.Parent = inventory
								v.Text = v.Name
							end
						end)
					end
				end
			end)
		end)
	end
end

Without giving any explanation, the video will not help us understand what issue you are currently facing. Please elaborate more on your issue, or at least on what/how you are trying to achieve this.

One thing I have found in your code (may not be related to your issue) is that you are parenting the weapons on the client, rather than on the server. You should be having the server parent the weapons in the Backpack (you can do this by using a remote event). You also don’t need the plrs.PlayerAdded:Wait() in your plr variable.

I have already fixed this bug, but thank you for your response.