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

How do i fix the disappearing of an important part of a tool?

Asked by 5 years ago
Edited 5 years ago

Hello, I have a problem with a tool, what i want to make is a sword that can put the blade in and out the in a blade protector(i'm not sure if its called blade protector) but after doing it, it removes an important part of the tool after few time after taking the blade out then putting it back in, rarely it doesn't, or takes longer than usual.

These are the scripts that i'm using(No errors until the blade is gone and the only error is that the blade is misisng)

Script to weld the tool:

tool = script.Parent

tool.Equipped:Connect(function()
    local weld = Instance.new("Weld")
    weld.Name = "weld1"
    weld.Parent = script.Parent.Handle2
    weld.Part0 = script.Parent.Handle2
    weld.Part1 = script.Parent.Parent:FindFirstChild("LeftHand")
    local weld2 = Instance.new("Weld")
    weld2.Name = "weld1"
    weld2.Parent = script.Parent.BladeProtectorPart
    weld2.Part0 = script.Parent.BladeProtectorPart
    weld2.Part1 = script.Parent.BladePart
end)

tool.Unequipped:Connect(function()
    local weldha1 = script.Parent.HandlePart:FindFirstChild("weld1")
    if weldha1 ~= nil then
        weldha1:Destroy()
    end
    local weldha2 = script.Parent.Handle2:FindFirstChild("weld1")
    if weldha2 ~= nil then
        weldha2:Destroy()
    end
    local weldbpp = script.Parent.BladeProtectorPart:FindFirstChild("weld1")
    if weldbpp ~= nil then
        weldbpp:Destroy()
    end
end)

Local Script to be able to put the blade in and out

local tool = script.Parent
local uis = game:GetService("UserInputService")
local out = false
local enabled = true

tool.Equipped:Connect(function()
    uis.InputBegan:Connect(function(input, gameprocess)
        if not enabled then return end
        enabled = false
        if input.KeyCode == Enum.KeyCode.E then
            local weldbpp = script.Parent.BladeProtectorPart:FindFirstChild("weld1")
            local weldha1 = script.Parent.HandlePart:FindFirstChild("weld1")
            local weldha2 = script.Parent.Handle2:FindFirstChild("weld1")
            if out == true then             
                out = false
                if weldha1 ~= nil then
                    weldha1:Destroy()
                end
                local weld01 = Instance.new("Weld")
                weld01.Name = "weld1"
                weld01.Parent = script.Parent.BladeProtectorPart
                weld01.Part0 = script.Parent.BladeProtectorPart
                weld01.Part1 = script.Parent.BladePart
            elseif out == false then
                out = true
                if weldbpp ~= nil then
                    weldbpp:Destroy()
                end
                local weld0 = Instance.new("Weld")
                weld0.Name = "weld1"
                weld0.Parent = script.Parent.HandlePart
                weld0.Part0 = script.Parent.HandlePart
                weld0.Part1 = script.Parent.Parent:FindFirstChild("RightHand")
            end
        end
        wait(0.2)
        enabled = true
    end)
end)

Pictures: https://imgur.com/a/Vy2w3vd

0
Does this occur randomly or after rapid succession of using the equip / unequip events, if its the latter, try adding a debounce SerpentineKing 3885 — 5y
0
I believe its random with higher chance of disappearing, like 70% to disappear and 30% not to disappear if not even less but i will try adding a debounce to see if it works richboifexekappa 89 — 5y
0
I just noticed, it already has debounce, also played with it a bit and didn't help, i wonder if the issue is the tool itself, will try another model richboifexekappa 89 — 5y

Answer this question