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 7 years ago

LocalScript in tool:

01local tool = script.Parent
02local char = tool.Parent.Parent.Character
03 
04local function onActivate()
05char.Head.Transparency = 1
06char['Right Arm'].Transparency = 1
07char['Left Arm'].Transparency = 1
08char.Torso.Transparency = 1
09char['Right Leg'].Transparency = 1
10char['Left Leg'].Transparency = 1
11 
12local function onUnequip()
13    char.Head.Transparency = 0
14char['Right Arm'].Transparency = 0
15char['Left Arm'].Transparency = 0
16char.Torso.Transparency = 0
17char['Right Leg'].Transparency = 0
18char['Left Leg'].Transparency = 0
19end
20end

1 answer

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

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

01local tool = script.Parent
02 
03local function onActivate()
04    local char = tool.Parent.Parent
05    char.Head.Transparency = 1
06    char['Right Arm'].Transparency = 1
07    char['Left Arm'].Transparency = 1
08    char.Torso.Transparency = 1
09    char['Right Leg'].Transparency = 1
10    char['Left Leg'].Transparency = 1
11end
12tool.Activated:Connect(onActivate)
13 
14local function onUnequip()
15    local char = tool.Parent.Parent
View all 23 lines...

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:

01function setTransparency(trans)
02    local char = script.Parent.Parent
03    for _,v in pairs(char:GetDescendants()) do
04        if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
05            v.Transparency = trans
06        end
07    end
08end
09script.Parent.Equipped:Connect(function()
10    setTransparency(1)
11end)
12script.Parent.Unequipped:Connect(function()
13    setTransparency(0)
14end)
Ad

Answer this question