Hi all! I've been trying to script a tool that does two things when activated: changes color from red to green (and vice versa) and changes the transparency of all of the player's character's body parts, excluding the face decal, from 0 to 1 (and vice versa). Originally, in order to do this, I thought that I could have two variables that store a Color3 for green and the integer 1. Then, I would change the Color property of the tool (which is just a part named "Handle") to the value in the color variable, and change the value of the color variable to the value of the color of the tool. This works perfectly fine. The problem arises when I try to do the same for the transparency of the player's character's body parts.
Here is the original script I used:
local tool = script.Parent
local handle = tool.Handle
local storedColor = Color3.fromRGB(0,255,0)
local storedTransparency = 1
tool.Activated:Connect(function()
handle.Color, storedColor = storedColor, handle.Color
for I,V in pairs(tool.Parent:GetChildren()) do
if V.ClassName == "MeshPart" or V.ClassName == "Part" and V.Name ~= "HumanoidRootPart" then
V.Transparency, storedTransparency = storedTransparency, V.Transparency
end
end
end)
This is what happens when I click once: https://imgur.com/a/wfHhlEP
I figured that this was just a problem with how Roblox handled the multiple assignment for transparency, so I changed it to some if statements:
local tool = script.Parent
local handle = tool.Handle
local storedColor = Color3.fromRGB(0,255,0)
tool.Activated:Connect(function()
handle.Color, storedColor = storedColor, handle.Color
for I,V in pairs(tool.Parent:GetChildren()) do
if V.ClassName == "MeshPart" or V.ClassName == "Part" and V.Name ~= "HumanoidRootPart" then
if V.Transparency == 0 then
V.Transparency = 1
else
V.Transparency = 0
end
end
end
end)
This fixed the problem (as can be seen here: https://imgur.com/a/preavKB) but the addition of these lines personally bothers me, I would prefer doing multiple assignment. Does anyone know whether there was something wrong with my original script with multiple assignment, or whether multiple assignment is simply not possible in this scenario?
Thanks in advance!
