How Player become invisible when sit down and become visible when unsit

How i make a script for player become invisible when sit down?
Im making a model car

but i need that the player become invisible when sit down for save space at the car


Have you tried this code on the DevHub?

I already tried it and it didnt worked

You just gotta make a childadded and childremoved event on a seat then check if it is a weld get part1 of it (this will be humanoidrootpart) then make an for I, v in pairs loop from humanoidrootpart.parent:GetChildren() and the the transparency of v to 1

But the method from @imAlex_30 is better with occupant

Well, the resources have already been provided, so it’s a matter of utilising them.
Using the API reference, there’s a code snippet at the bottom that handles if a player is sitting in a seat or not.

Seats have a property called Occupant which is the humanoid sitting in the seat. I would use code provided in that article with a combination of a for loop, through a function. This is so you don’t have to repeat the for loop twice. The function is used in correlation to what you input into its arguments when you call it. When we are for-looping, we want to ignore the HumanoidRootPart, as it’s already transparent, using the ~= operator.

I’m not sure how setting the transparency will save space.

but i need that the player become invisible when sit down for save space at the car

local Players = game:GetService("Players")
local seat = script.Parent
local currentplayer = nil

	local humanoid = seat.Occupant
	if humanoid then
		local character = humanoid.Parent
		local player = Players:GetPlayerFromCharacter(character)
		if player then
			print(player.Name.." has sat down")
			currentplayer = player
			Invisible(character, 1) -- Set transparency to 1
	if currentplayer then
		print(currentplayer.Name.." has got up")
		local character = currentplayer.Character
			Invisible(character, 0) -- -- Set transparency to 0
			currentplayer = nil

function Invisible(character, transparency) -- A function that identifies the revelant character, and changes the transparency according to what you input when you call the function.
	for _, parts in pairs(character:GetDescendants()) do
		if parts:IsA("BasePart") and parts.Name ~= "HumanoidRootPart" or parts:IsA("Decal") then
			parts.Transparency = transparency

These script dont work for me, try it first, when i jump the player don’t are visible again

I tried the script on, it worked, but the face is still visible

player.Character.Head.face.Transparency = 1

1 Like