I just want to preface that I am not good with scripting at all but I am attempting to make a seatbelt system where the parts named “seatbelt” become visible when it detects a player has sat down and then goes invisible when it detects that a player has exited the seat.
So far I’ve managed to get the first fifty percent of what I’m trying to accomplish working but I am having trouble on the second half where it needs to detect when a player exits the seat.
I’ve spent the last few hours looking for anybody having even remotely the same or similar issue as I am having but could not find anything. So I’m just asking for help here cause I don’t know what else to do, lol.
local Seat = script.Parent
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant ~= nil then
--Player is seated
else
--Player has left the seat
end
end)
local Seat = script.parent
local function SetTransparency(Value)
for i,x in pairs(Seat:GetChildren()) do
if x.Name == "seatbelt" then
x.Transparency = Value
end
end
end
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant == nil then
SetTransparency(1)
else
SetTransparency(0)
end
end)
I added an else statment, as adamaniac said; and a function that set the transparency of the seat belt.
Hope that helps!