PropertyChangedSignal not working?

I’ve been making a script and have used a GetPropertyChanged, but it doesn’t seem to work. Does anyone have any ideas? Tried to look at some other posts but could not figure it out.

local function OccupantChanged()
	if seat.Occupant then
		print("hi")
			else
			print("hi")
		end
	end
	seat:GetPropertyChangedSignal("Occupant"):Connect(function(OccupantChanged)
		end)
		end)
		end)
	end
1 Like

Idk man, propertychangedsignal always works bad for me too: maybe use .changed?

1 Like

GetPropertyChangedSignal works, how you’re using it is wrong though. What you’re doing here is connecting an anonymous function to the returned signal and having OccupantChanged as a parameter for the function.

Close the function first then connect it by the variable.

local function OccupantChanged()
    if seat.Occupant then
        print("hi occupant")
    else
        print("hi no occupant")
    end
end

seat:GetPropertyChangedSignal("Occupant"):Connect(OccupantChanged)

Doesn’t seem to work either.
(The reason why I have many ends is because this is only the bottom half of my script, not sure.

local function OccupantChanged()
	if seat.Occupant then
		print("Seat is occupant")
		else
			print("seat is not occupant")
		end
	end
seat:GetPropertyChangedSignal("Occupant"):Connect(OccupantChanged)
	end
	end)
	end)
	end

Can’t exactly help you if you just tell me “it doesn’t work”. I need details. Please be sure to debug your own scripts or check the console first and include that kind of information if something doesn’t work so you can be better helped.

Is this a script or LocalScript? If a LocalScript; it won’t run in Workspace (if it’s there). Put it in StarterPlayerScripts and use @colbert2677’s solution.

If it’s a script in the seat, it should work.

Show your output next time, it’ll help a lot.

(Either way use colbert’s solution)

Example:

local seat = workspace.Seat -- edit to your seat path
function newOccupant(occ)
    if occ ~= nil then
        print(occ.Parent.Name,"is the occupant!")
    else
        print("No occupant anymore.")
    end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(newOccupant)
1 Like

Maybe provide the rest of the script as this bit of code might not even run depending on what else is going on. Providing a small snippet (which Colbert fixed for you) and discovering it still “doesn’t work” suggests the problem is a bit wider.

Check for similar issues to what colbert found - places where you’ve not connected events properly and where you’ve defined anonymous functions when you meant to provide a predefined callback instead.

I did the exact same thing yesterday and they told me that local scripts won’t run in Workspace so that can be the reason.