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

I am trying to make a toggle invisibility, how would I do so?

Asked by 3 years ago
Edited 3 years ago

It works but there is two problems with it, one, it doesn't make hats and faces invisible too and two, when I toggle back to visible then it adds a grey block around the players torso.

local event = script.InvisFunction
local Val = script.Parent.Hidden.Value

event.OnServerEvent:Connect(function(player)
    if Val == false then
    Val = true
    local character = player.Character or workspace:FindFirstChild(player.Name)
        for k, v in pairs(character:GetChildren()) do
        if v:IsA('BasePart') then
            v.Transparency = 1
            local decal = v:FindFirstChild('Decal')
            if decal then
                decal.Transparency = 1
            end
        end
            end
    else
        Val = false
    local character = player.Character or workspace:FindFirstChild(player.Name)
        for y, t in pairs(character:GetChildren()) do
        if t:IsA('BasePart') then
            t.Transparency = 0
            local decal = t:FindFirstChild('Decal')
            if decal then
                decal.Transparency = 0
            end
        end
        end
    end
end)

0
What kind of toggle invisibility? Making other people invisible? or making every one? Retallack445 75 — 3y
0
A button that you click to make yourself invisible but shows for everyone. Synavant 6 — 3y
0
Like how some murder mystery games are when they use the ghost ability and it makes them invisible for a certain period of time when they are murderer but make it toggle instead. Synavant 6 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I suggest creating a folder inside of ServerStorage to store the player's Accessories.

Also that 'grey block' that is around the player's torso is the HumanoidRootPart. It's default transparency is set to 1, and when you're getting all the parts inside the Character you're also getting the HumanoidRootPart and setting the transparency to 0.

local ss = game:GetService("ServerStorage")
local Event = game.ReplicatedStorage.InvisEvent
local isInvis = false

Event.OnServerEvent:Connect(function(Player)

    local Character = Player.Character

    if isInvis == true then
        isInvis = false

        for _, part in pairs(Character:GetDescendants()) do

            if part:IsA("BasePart") or part:IsA("MeshPart") then
                part.Transparency = 1

            elseif part:IsA("Accessory") or part:IsA("FaceInstance") then

                if not ss.PlayerAccessories:FindFirstChild(Player.Name) then
                    local PlayerAccessoryFolder = Instance.new("Folder")
                    PlayerAccessoryFolder.Name = Player.Name
                    PlayerAccessoryFolder.Parent = ss.PlayerAccessories
                end
                part.Parent = ss.PlayerAccessories[Player.Name]
            end
        end 
    else
        isInvis = true

        if ss.PlayerAccessories:FindFirstChild(Player.Name) then

            for _, Accessory in pairs(ss.PlayerAccessories[Player.Name]:GetChildren()) do
                if not Accessory:IsA("FaceInstance") then
                    Accessory.Parent = Character
                else
                    Accessory.Parent = Character.Head
                end
            end

            for _, part in pairs(Character:GetDescendants()) do
                if part:IsA("BasePart") or part:IsA("MeshPart") then
                    if part.Name ~= "HumanoidRootPart" then
                        part.Transparency = 0
                    end
                end
            end
        end
    end
end)

Hope this helps.

If you have any questions just post a comment to this answer and I'll try to answer them.

0
Is there anyway you could just add to the script I have to make it where the hat and face go invisible as well? Synavant 6 — 3y
0
Accessories don't have a Transparency option so there's not really any other way to make them 'invisible' other than moving them to another location and back. xInfinityBear 1777 — 3y
Ad

Answer this question