I need to make it so when a player seats on a “Seat” it becomes transparent and when he gets out of the seat he will be visible as he was before!
I got it working when it’s seated (he became transparent), but when he leaves I don’t know how to make him transparent again?
I’ve tried many posiblities but nothing worked.
Code:
local part = script.Parent
local char
while wait(0.2) do
if part.Occupant then
char = part.Occupant.Parent
for i,v in pairs(char:GetDescendants()) do
if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("Decal") then
v.Transparency = 1
print("doing")
if not part.Occupant then
break
end
end
end
else
print("no seat")
end
end
local Players = game:GetService("Players")
local seat = Instance.new("Seat")
seat.Anchored = true
seat.Position = Vector3.new(0, 1, 0)
seat.Parent = workspace
local currentPlayer = nil
local function onOccupantChanged()
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
return
end
end
if currentPlayer then
print(currentPlayer.Name .. " has got up")
currentPlayer = nil
end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(onOccupantChanged)
This code is better for many reasons, first of all it is not a while loop, and secondly you don’t have to loop over char:GetDescendants(). I still recommend you to read the roblox documentation (the link above) to have a better understanding of what this script does.
From there, you can modify the script to hide and display whatever you want on the seat!