Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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 :(

2 comments

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?

0

yes! the script works in a part, but not a seat!

1 answer

✓ Accepted answer

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)

6 comments

0

I will try this after school -- thanks

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.

0

what are you talking about, hayday??

0

Still doesn't work. When I sit in the seat it does not invisiblize me

0

ah shoot- i used the wrong function. i meant to use GetPropertyChangedSignal. i've updated my answer to reflect the update

0

It Works!! Thank You!!

This discussion is preserved as it was. New answers, comments, and votes are closed.