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

My R6 invisibility tool script isn't working and nothing shows in output. Why?

Asked by 6 years ago

LocalScript in tool:



local tool = script.Parent local char = tool.Parent.Parent.Character local function onActivate() char.Head.Transparency = 1 char['Right Arm'].Transparency = 1 char['Left Arm'].Transparency = 1 char.Torso.Transparency = 1 char['Right Leg'].Transparency = 1 char['Left Leg'].Transparency = 1 local function onUnequip() char.Head.Transparency = 0 char['Right Arm'].Transparency = 0 char['Left Arm'].Transparency = 0 char.Torso.Transparency = 0 char['Right Leg'].Transparency = 0 char['Left Leg'].Transparency = 0 end end

1 answer

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

You have to link the functions to the Equipped and Activate events (and also move your ends around):

local tool = script.Parent

local function onActivate() 
    local char = tool.Parent.Parent
    char.Head.Transparency = 1
    char['Right Arm'].Transparency = 1
    char['Left Arm'].Transparency = 1
    char.Torso.Transparency = 1
    char['Right Leg'].Transparency = 1
    char['Left Leg'].Transparency = 1
end
tool.Activated:Connect(onActivate)

local function onUnequip()
    local char = tool.Parent.Parent
    char.Head.Transparency = 0
    char['Right Arm'].Transparency = 0
    char['Left Arm'].Transparency = 0
    char.Torso.Transparency = 0
    char['Right Leg'].Transparency = 0
    char['Left Leg'].Transparency = 0
end
tool.Unequipped:Connect(onUnequip)

But a better way to do it might be to iterate through the children of the character and set the transparency of all the parts to 0/1:

function setTransparency(trans)
    local char = script.Parent.Parent
    for _,v in pairs(char:GetDescendants()) do
        if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
            v.Transparency = trans
        end
    end
end
script.Parent.Equipped:Connect(function()
    setTransparency(1)
end)
script.Parent.Unequipped:Connect(function()
    setTransparency(0)
end)
Ad

Answer this question