I have spent hours looking for information, this is the best version of the script i did
I see that occupant is a string but i dont know any other option
Output:
changedsignal - Server - Script:9
cargui cloned - Server - Script:11
Workspace.Seat.Script:8: attempt to index nil with ‘Parent’ - Server - Script:8
For some reason the script error only appeared on the second trigger
local Players = game:GetService("Players")
local Seatf = script.Parent
local varieble = true
Seatf:GetPropertyChangedSignal("Occupant"):Connect(function()
local player = Players:GetPlayerFromCharacter(script.Parent.Occupant.Parent)
print("changedsignal")
if varieble == true then
print("cargui cloned")
player.PlayerGui.CarGui.Enabled = true
varieble = false
else
player.PlayerGui.CarGui.Enabled = false
varieble = true
end
end)
local Players = game:GetService("Players")
local seat = script.Parent
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
local player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
seat:SetAttribute("Player", player.UserId) -- instances not supported
-- continue
else
local player = Players:GetPlayerByUserId(seat:GetAttribute("Player"))
print(player.Name .. " was here")
end
end)
I’m sorry, but I can’t replicate that issue. seat.Occupant is always humanoid. The code works flawlessly on my end, even when I reset while sitting.
Look at line 6 in my example. It only runs if occupant exists. When player stands up, it becomes nil and your code errors by attempting to index it with .Parent.