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

Touch a part and your characters transparncy = 0.5 ?

Asked by 6 years ago

would anyone have a clue how to do this?

0
Humanoids don't have transparency I beleive. FlippinAwesomeCrew 62 — 6y
0
you cant access the torso? lopehole12 0 — 6y
0
did you attempt this on your own? Vulkarin 581 — 6y

2 answers

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

It would be something like this:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        for _,v in pairs(hit.Parent:GetChildren()) do
            if v:IsA("BasePart") then
                v.Transparency = 0.5
            end
        end
    end
end)
Ad
Log in to vote
0
Answered by 6 years ago

Hey lopehole12,

The above answer would work only to the extent that it hides your BodyParts, but the face and accessories would still be able to be seen. So, the script that I am about to provide you with is explained and efficient. So, here I go.

Script

local part = script.Parent; -- The part that is being touched.

part.Touched:Connect(function(obj) -- Anonymous function
    local hum = obj.Parent:FindFirstChild("Humanoid"); -- Humanoid of the player(If it is a player that touched the part.)
    if hum then -- Checks if the humanoid exists to see if it is a player.
        local char = obj.Parent; -- The character of the player
        local objs = char:GetChildren(); -- A table with all of the Userdata values/Instances/Objects inside of the Character.

        for _, object in next, objs do -- A for each iteration that goes through the said table and gives a variable to each instance/userdata value it is iterating through as 'object'
            if object:IsA("BasePart") then -- Checks if it's a Basepart(Basically if it is a limb)
                object.Transparency = 1; -- Makes the part Transparent.
            end -- end for the BasePart if statement.

            if object:IsA("Accessory") or object.Name == "Head" then -- Checks if it is an accessory or if the object is the head.
                local irr = object:FindFirstChild("Handle") or object:FindFirstChild("face"); -- If it is an Accessory, it should have a child called "Handle" and if it is a Head, it should have the child called Face, making both of these transparent helps get rid of the problem of the Face and Accessories being visible. The 'or' is like a ternary operator, it either goes with the handle or with the face.
                irr.Transparency = 1; -- Makes the part/decal invisible.
            end -- end for the Accessory, Head if statement
        end -- end for the for each iteration
    end -- end for the humanoid if statement
end) -- end for the function as a whole.

Well, I hope I helped and have a nice day.

~~ KingLoneCat

Answer this question