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

How do i Save Character as a Value for when a tool Unequips/Equips?

Asked by 10 years ago

I want to know how you can Call a Character's Model in the workspace up locally to the tool when you unequip/Equip

This is what i have so far:

Handle = nil
local Character = nil
Tool = script.Parent

function onUnequipped()
    if script.Parent.Parent == workspace or script.Parent.Parent.className ~= "Backpack" then
        return
    end

    local char = script.Parent.Parent.Parent.Character
    if char ~= nil then
        local torso = char:findFirstChild("Torso")
        local tool = char:findFirstChild(script.Parent.Name)
        if torso ~= nil and tool == nil then
            local model = Instance.new("Model")
            model.Name = script.Parent.Name
            model.Parent = char

            handle = script.Parent.Handle:clone()
            handle.Part.BottomBlade.Transparency = 1
            handle.Part.BottomBlade.PointLight.Enabled = false
            handle.Part.TopBlade.Transparency = 1
            handle.Part.TopBlade.PointLight.Enabled = false
            handle.CanCollide = false
            handle.Name = script.Parent.Name
            handle.Parent = model

            local weld = Instance.new("Weld")
            weld.Name = "BackWeld"
            weld.Part0 = torso
            weld.Part1 = handle
            weld.C0 = CFrame.new(-1,-1.02,0.1)
            weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(330),0)
            weld.Parent = handle
            script.Parent.Handle.UnEquip:Play()

    Character.Arm1.Handle.Transparency = 1
    Character.Arm1.TopBlade.Transparency = 1

    Character.Arm1.Handle2.Transparency = 1
    Character.Arm1.TopBlade2.Transparency = 1

    Character.Arm2.Handle.Transparency = 1
    Character.Arm2.TopBlade.Transparency = 1

    Character.Arm2.Handle2.Transparency = 1
    Character.Arm2.TopBlade2.Transparency = 1
        end
    end
end

script.Parent.Unequipped:connect(onUnequipped)

function onEquipped()
    if handle ~= nil then 
        handle.Parent:remove()
        script.Parent.Handle.Equip:Play()

    Character = Tool.Parent
    if not Character then return end

    local Humanoid = Character:FindFirstChild("Humanoid")
    if not Humanoid then return end

    Character.Arm1.Handle.Transparency = 0
    Character.Arm1.TopBlade.Transparency = 0

    Character.Arm1.Handle2.Transparency = 0
    Character.Arm1.TopBlade2.Transparency = 0

    Character.Arm2.Handle.Transparency = 0
    Character.Arm2.TopBlade.Transparency = 0

    Character.Arm2.Handle2.Transparency = 0
    Character.Arm2.TopBlade2.Transparency = 0
    end
end

script.Parent.Equipped:connect(onEquipped)

0
It's glitched after i do this? thejeterman 0 — 10y

Answer this question