Hi is it possible to make the player invisible when he sits on a seat, then get uninvisible when he gets off it?? How would I be able to do this --Thanks for any help
the first thing you need to make is a function that will change character's transparency to your specified value, you loop through every descendant of the character (children, their children and so on) and check if that descendant is a part, if that's so then change its transparency.
local function Set_Character_Transparency(character, transparency) for _, part in character:GetDescendants() do if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then part.Transparency = transparency end end end
next you need to make player invisible when he sits down, say you have a seat:
local seat = workspace.Seat
then you want to know when someone sits on this seat, you can use Seat.Occupant, this property shows who is currently sitting on the seat, if no-one is sitting then it's nil, otherwise it's Humanoid of the person who's sitting.
everytime this property changes you want to make the sitting character invisible, you just run the Set_Character_Transparency function with transparency being 1 (which is invisible). to run a function when the property changes, you want to use :GetPropertyChangedSignal which will do exactly that:
local seat = workspace.Seat local function Set_Character_Transparency(character, transparency) for _, part in character:GetDescendants() do -- never change transparency of humanoid root part, it's always invisible if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then part.Transparency = transparency end end end seat:GetPropertyChangedSignal("Occupant"):Connect(function() print("Occupant changed:", seat.Occupant) -- seat.Occupant may be nil if no one is sitting, that's why there's if if seat.Occupant then -- seat.Occupant.Parent is the character (Humanoid is in Character makes sense) Set_Character_Transparency(seat.Occupant.Parent, 1) end end)
but now you want to make character visible back again, for that you need to remember the humanoid who last sit on the seat, and when the seat occupant changes again you check: was there anyone sitting before? if there was someone sitting before and the seat occupant changed then it means that currently there is no-one sitting, so we make the last sitting character back visible.
local seat = Workspace.Seat -- last seating character local LastOccupant = nil local function Set_Character_Transparency(character, transparency) for _, part in character:GetDescendants() do if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then part.Transparency = transparency end end end seat:GetPropertyChangedSignal("Occupant"):Connect(function() local occupant = seat.Occupant if occupant == nil and LastOccupant then -- if occupant is nil (no one is seating) and someone was sitting before, we make -- him back visible Set_Character_Transparency(LastOccupant, 0) else -- otherwise if occupant is not nil then someone just seated so we set him -- as the last seating occupant and make him invisible Set_Character_Transparency(occupant.Parent, 1) LastOccupant = occupant.Parent end end)
https://developer.roblox.com/en-us/api-reference/function/Instance/GetPropertyChangedSignal