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

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

Asked by
Foridex 46
5 years ago
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

Log in to vote
0
Answered by
T1mes 230 Moderation Voter
5 years ago
Edited 5 years ago

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

Ad

Answer this question