Print("TEST") only prints when car gets spawned in

Local script in StarterPlayerScripts

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local finder = workspace:WaitForChild(player.Name.."'s Car")
task.wait(.6)
local CarName = finder.CarName.Value
local PathToSeat = finder.DriveSeat


local function handleOccupantChange()
	print("TEST")--Only print when car gets spawned in
	end


PathToSeat:GetPropertyChangedSignal("Occupant"):Connect(function(property)
	print("TEST 1")
	if property == "Occupant" then
		
		handleOccupantChange()
	else
		
	end
end)


handleOccupantChange()

I am try to achieve is when a player sits in the DriveSeat it print TEST. TEST 1 prints fine. Why won’t it print TEST when player is sitting in drive seat? But it will print TEST when I first spawn in the car.

the if check in the getpropertychangedsignal is useless because it will only fire when the occupant property gets changed, also getpropertychangedsignal returns a rbxscriptsignal not which property changed

1 Like

How can I achieve what I am trying to do then?

because you are getting the signal for a property being changed and then asking if that property got changed using a variable that doesnt exist from that event

this should fix it

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local finder = workspace:WaitForChild(player.Name.."'s Car")
task.wait(.6)
local CarName = finder.CarName.Value
local PathToSeat = finder.DriveSeat

local function handleOccupantChange()
	print("TEST")--Only print when car gets spawned in
end

PathToSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	print("TEST 1")
	
	local occupant = PathToSeat.Occupant
	
	if occupant then
		handleOccupantChange()
	else

	end
	
end)

handleOccupantChange()
1 Like

Thank u it fixed the problem!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.