I was trying to make a script where if the player is sitting in a chair, everything on that player’s body would turn invisible, including the avatar items on that player. But if the player jumps out of the seat, everything on his body turns invisible again. The script below didn’t work, can someone please help me fix it?
local Seat = script.Parent
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant ~= nil then
local Char = Seat.Occupant.Parent
for i,v in pairs(Char:GetChildren()) do
v.Transparency = 1
if v:IsA("Accessory") then
v.Handle.Transparency = 1
end
end
if Seat.Occupant == nil then
local Char = Seat.Occupant.Parent
for i,v in pairs(Char:GetChildren()) do
v.Transparency = 0
if v:IsA("Accessory") then
v.Handle.Transparency = 0
end
end
end
end
end)
1 Like
It’s not that your character turned invisible, but if you notice, your second condition “Seat.Occupent==nil” states that if there are no occupants, then this would fire, which it does. The problem here is when you do local Char=Seat.Occupant.Parent, there is no parent to begin with. You should store the player that sits in the seat so you can change the when the player hops out of the seat.
1 Like
I don’t know how to do that. Can you write me a script?
The following answer I have stated is mainly consist of basic foundations, specifically variables. I can make you a pseudo code, but it’s best if you try it on your own first.
local storePlayer = nil
detect seat change()
if seat have occupent then
make seat occupant turn invisible
store player in variable
else -- if player exit the seat
make "storePlayer" visible
make variable equal nil
end
end
3 Likes
I forgot to tell you, I’m a complete beginner, so I don’t know how any of that stuff works