I cant figure it out how to solve this

  1. **What do you want to achieve?
    having problem with tween

  2. What is the issue?
    works fine but when equip other tool it give an error

before:

after:

  1. What solutions have you tried so far?
    nothing

local player = game:GetService("Players").LocalPlayer
local GUI = player.PlayerGui:WaitForChild("GunGUI")
local tool = script.Parent

local main = GUI.Main
local HL = main.HL
local HR = main.HR
local VD = main.VD
local VU = main.VU
local center = main.Center

local sprint = false
--crosshair move
tool.Equipped:Connect(function()
	player.Character.Humanoid.Running:Connect(function(speed)
		if speed > 10 then
			HL:TweenPosition(
				UDim2.new(0, -97, 0, 0),
				"Out",
				"Linear",
				0.18,
				true
			)
			HR:TweenPosition(
				UDim2.new(0, 90, 0, 0),
				"Out",
				"Linear",
				0.18,
				true
			)
			VD:TweenPosition(
				UDim2.new(0, 0, 0, 90),
				"Out",
				"Linear",
				0.18,
				true
			)
			VU:TweenPosition(
				UDim2.new(0, 0, 0, -97),
				"Out",
				"Linear",
				0.18,
				true
			)

		else
			HL:TweenPosition(
				UDim2.new(0, -57, 0, 0),
				"Out",
				"Linear",
				0.18,
				true
			)
			HR:TweenPosition(
				UDim2.new(0, 50, 0, 0),
				"Out",
				"Linear",
				0.18,
				true
			)
			VD:TweenPosition(
				UDim2.new(0, 0, 0, 50),
				"Out",
				"Linear",
				0.18,
				true
			)
			VU:TweenPosition(
				UDim2.new(0, 0, 0, -57),
				"Out",
				"Linear",
				0.18,
				true
			)
		end
	end)
end)

--sprint

player.Character.Humanoid.Running:Connect(function(speed)
	if speed > 16 then
		HL.Visible = false
		HR.Visible = false
		VD.Visible = false
		VU.Visible = false
	else
		HL.Visible = true
		HR.Visible = true
		VD.Visible = true
		VU.Visible = true
	end
end)

tool.Equipped:Connect(function()
	VU.Visible = false
	VU.Transparency = 1
end)

--disable the viewmodel via unequip
tool.Unequipped:Connect(function()
	VU.Transparency = 1
end)

Copy and paste the script into each tool you want it to work in.

Add a wait for child to grab your HL, HR etc objects. They may be null due to loading order.

local HL = main:WaitForChild(“HL”)
--etc

Including the Main aswell.

Local script can run before the Guis load

still dosnt work for me idk why

When you equip the tool it looks like you’re connecting to the Humanoid.Running event on the character’s humanoid. The problem you’re seeing is that you never disconnect that event, so as the tool is unequipped and the gun’s parts are no longer in the Workspace that event is still firing and trying to tween parts that aren’t in the workspace. You could fix this like so:

local player = game:GetService("Players").LocalPlayer
local GUI = player.PlayerGui:WaitForChild("GunGUI")
local tool = script.Parent

local main = GUI.Main
local HL = main.HL
local HR = main.HR
local VD = main.VD
local VU = main.VU
local center = main.Center

local sprint = false
local running_listener = nil
--crosshair move
tool.Equipped:Connect(function()
	running_listener = player.Character.Humanoid.Running:Connect(function(speed)
		if speed > 10 then
			HL:TweenPosition(
				UDim2.new(0, -97, 0, 0),
				"Out",
				"Linear",
				0.18,
				true
			)
			HR:TweenPosition(
				UDim2.new(0, 90, 0, 0),
				"Out",
				"Linear",
				0.18,
				true
			)
			VD:TweenPosition(
				UDim2.new(0, 0, 0, 90),
				"Out",
				"Linear",
				0.18,
				true
			)
			VU:TweenPosition(
				UDim2.new(0, 0, 0, -97),
				"Out",
				"Linear",
				0.18,
				true
			)

		else
			HL:TweenPosition(
				UDim2.new(0, -57, 0, 0),
				"Out",
				"Linear",
				0.18,
				true
			)
			HR:TweenPosition(
				UDim2.new(0, 50, 0, 0),
				"Out",
				"Linear",
				0.18,
				true
			)
			VD:TweenPosition(
				UDim2.new(0, 0, 0, 50),
				"Out",
				"Linear",
				0.18,
				true
			)
			VU:TweenPosition(
				UDim2.new(0, 0, 0, -57),
				"Out",
				"Linear",
				0.18,
				true
			)
		end
	end)
end)

--sprint

player.Character.Humanoid.Running:Connect(function(speed)
	if speed > 16 then
		HL.Visible = false
		HR.Visible = false
		VD.Visible = false
		VU.Visible = false
	else
		HL.Visible = true
		HR.Visible = true
		VD.Visible = true
		VU.Visible = true
	end
end)

tool.Equipped:Connect(function()
	VU.Visible = false
	VU.Transparency = 1
end)

--disable the viewmodel via unequip
tool.Unequipped:Connect(function()
    if running_listener then
        running_listener:Disconnect()
        running_listener  = nil
    end
	VU.Transparency = 1
end)

Notice how I’ve added the running_listener variable so that we can disconnect the Humanoid.Running signal listener once we unequip the tool. I’ve also added a check in the tool.Unequipped signal listener to disconnect that event.

You have to do.

Enum.EasingDirection.Out,
Enum.EasingStyle.Linear

The script will consider the things in qutations as strings. Not Enum values.

You can use strings as substitutes for enums. It’s not a great practice but it does work.

try this. You have to have a function callback at the end. If you don’t have one or dont want one do nil at the end here:

HL:TweenPosition(
	UDim2.new(0, -97, 0, 0),
	Enum.EasingDirection.Out,
	Enum.EasingDirection.Out,
	0.18,
	true,
	nil -- this is nil because there is no FUNCTION call back.
)

This is also unnecessary. The issue he’s having is specifically that he never disconnects the Humanoid.Running signal listener in his tool.Equipped logic. There’s nothing wrong with his tweens.

Try using tween service instead of tween position.

Maybe you can’t tween that specific tool because of a weld or something inside of it.