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

How to make this script invisiblize you when you sit in a seat??

Asked by 1 year ago

Hi I want this script to invisible people when you sit in a seat. And when you not touch it uninvisibles you. Script:

script.Parent.Touched:Connect(function(plr)
    if plr.Parent:FindFirstChild("Humanoid") then
        for i, v in pairs(plr.Parent:GetChildren()) do
            if v:IsA("BasePart") then
                v.Transparency = 1
            end
            if v:IsA("Accessory") then
                v.Handle.Transparency = 1
                for index, value in pairs(v.Handle:GetDescendants()) do
                    if value:IsA("ParticleEmitter") then
                        value.Transparency = NumberSequence.new(1)
                    end
                end
            end
        end
        plr.Parent.Head.face.Transparency = 1
    end
end)
script.Parent.TouchEnded:Connect(function(plr)
    if plr.Parent:FindFirstChild("Humanoid") then
        for i, v in pairs(plr.Parent:GetChildren()) do
            if v:IsA("BasePart") then
                v.Transparency = 0
            end
            if v:IsA("Accessory") then
                v.Handle.Transparency = 0
                for index, value in pairs(v.Handle:GetDescendants()) do
                    if value:IsA("ParticleEmitter") then
                        value.Transparency = NumberSequence.new(0)
                    end
                end
            end
        end
        plr.Parent.Head.face.Transparency = 0
        plr.Parent.HumanoidRootPart.Transparency = 1
    end
end)

What I have tried is changing basepart to Seat but it didn't work :(

1
Do you mean that when players sit in it will invisible them and when they get out of the seat it visible them again? bebokhouja2 38 — 1y
0
yes! the script works in a part, but not a seat! blue_bunny0fficl 98 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

You can use a seat's Occupant property and the GetPropertyChangedSignal signal to detect when a player starts to sit in a seat:

local seat = script.Parent
local PreviousHumanoid = nil

local function Sat()
    local Humanoid = seat.Occupant
    if (Humanoid ~= nil) then
        -- player entered seat
        PreviousHumanoid = Humanoid
        for i, v in pairs(Humanoid.Parent:GetChildren()) do
            if v:IsA("BasePart") then
                v.Transparency = 1
            end
            if v:IsA("Accessory") then
                v.Handle.Transparency = 1
                for index, value in pairs(v.Handle:GetDescendants()) do
                    if value:IsA("ParticleEmitter") then
                        value.Transparency = NumberSequence.new(1)
                    end
                end
            end
        end
        Humanoid.Parent.Head.face.Transparency = 1
    else
        -- player left seat
        if (PreviousHumanoid.Parent == nil) then
            return -- check if the humanoid still exists (check if player left)
        end
        Humanoid = PreviousHumanoid
        for i, v in pairs(Humanoid.Parent:GetChildren()) do
            if v:IsA("BasePart") then
                v.Transparency = 0
            end
            if v:IsA("Accessory") then
                v.Handle.Transparency = 0
                for index, value in pairs(v.Handle:GetDescendants()) do
                    if value:IsA("ParticleEmitter") then
                        value.Transparency = NumberSequence.new(0)
                    end
                end
            end
        end
        Humanoid.Parent.Head.face.Transparency = 0
        Humanoid.Parent.HumanoidRootPart.Transparency = 1
    end
end

seat:GetPropertyChangedSignal('Occupant'):Connect(Sat)
0
I will try this after school -- thanks blue_bunny0fficl 98 — 1y
0
It didn't work :( There were no errors. I did fix plr function part because it was underlined. I tried it your way and the way how i fixed the plr part. blue_bunny0fficl 98 — 1y
0
what are you talking about, hayday?? loowa_yawn 383 — 1y
0
Still doesn't work. When I sit in the seat it does not invisiblize me blue_bunny0fficl 98 — 1y
View all comments (2 more)
0
ah shoot- i used the wrong function. i meant to use GetPropertyChangedSignal. i've updated my answer to reflect the update loowa_yawn 383 — 1y
0
It Works!! Thank You!! blue_bunny0fficl 98 — 1y
Ad

Answer this question