Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does the ManualWeld stop working after re-equipping the flashlight?

wait(0.1)
local light = script.Parent.Light
local pointlight = light.SpotLight
local tool = script.Parent
local click = script.Parent.Handle.Click
local equip = script.Parent.Handle.Equip
local weld = Instance.new("ManualWeld")
local player = game.Players.LocalPlayer

tool.Equipped:Connect(function(mouse)
	local character = script.Parent.Parent
	local arm = character:WaitForChild("Right Arm")
	
	-- Weld Portion --
	weld.Parent = character.Torso
	weld.Part0 = character.Torso
	weld.Part1 = arm
	weld.C0 = CFrame.new(1.5,0.5,-0.5) * CFrame.fromEulerAnglesXYZ(1.5,0,0)
	-- -- -- -- -- -- -- -- -
    equip:Play()
	print(arm.Name)
    mouse.Button1Down:Connect(function()
		for i = 1,3 do
			weld.C0 = weld.C0 * CFrame.new(0,0.05,0) * CFrame.fromEulerAnglesXYZ(-0.05,0,0)
			wait()
		end
        pointlight.Enabled = not pointlight.Enabled
        click:Play()
		for i = 1,3 do
			weld.C0 = weld.C0 * CFrame.new(0,-0.05,-0.0025) * CFrame.fromEulerAnglesXYZ(0.05,0,0)
			wait()
		end
    end)
end)
tool.Unequipped:connect(function()
	local character = player.Character
	local arm = character:WaitForChild("Right Arm")
	
	weld:Destroy()
	pointlight.Enabled = false
	print(arm.Name)
	arm.Transparency = 0
	click:Play()
end)

It works upon equipping it for the first time, although after re-equipping it, it produces a Parent Property Locked error on the ManualWeld.

The weld's parent/Part0 is Torso and the Part1 is Right Arm.

1 answer

✓ Accepted answer

Your problem is you're destroying the weld when you unequip the tool and nothing is re-creating it when you re-equip it

also use :Connect() instead of :connect() as it is depricated

This discussion is preserved as it was. New answers, comments, and votes are closed.