Function isn't running useing :GetPropertyChangedSignal property

I have spent roughly 45 minutes now looking at various forums to find out how to fix this and have asked around if nothing I can find will explain this to me, Thing this is being used for is so that if you enter the car the other prompts that let you sit in other seats will un-enable themselves, That is all working perfectly well.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Seat = script.Parent

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	print("Property Changed")
	if Seat.Occupant == Player.Character.Humanoid then
		print("Player in Seat")
		script.Parent.Parent.Body.FrontLeft.ProximityPrompt.Enabled = false
		script.Parent.Parent.Body.Left.ProximityPrompt.Enabled = false
		script.Parent.Parent.Body.Right.ProximityPrompt.Enabled = false
	else
		print("Player Left Seat")
		script.Parent.Parent.Body.FrontLeft.ProximityPrompt.Enabled = true
		script.Parent.Parent.Body.Left.ProximityPrompt.Enabled = true
		script.Parent.Parent.Body.Right.ProximityPrompt.Enabled = true
	end
end)

I would appreciate any help what so ever.

2 Likes

If you look on the developer api for the seat, and look at the occupant property, you’ll notice it has the tag “Not Replicated”.
This means that the client will not be told that the server has set the seat occupant to something else.
You will want to use a remote event instead.

2 Likes

Probably do something like:

local players = game:GetService("Players")

local seat = script.Parent

seat.Changed:Connect(function(property)
	local occupant = seat.Occupant
	if property ~= "Occupant" then
		return 
	end
	if occupant then
		local character = occupant.Parent
		local humanoid = character.Humanoid
		local player = players:GetPlayerFromCharacter(character)
		if player then
			-- ..
		end
	else
		-- ..
	end
end)
1 Like

Will I compare the player.character.humanoid too it?

1 Like

If you use a remote event, the server can selectively fire the event to only a single player (that being the player that seated). I.e, you don’t actually have to perform any humanoid checks since the server just fires to whichever player seated.

2 Likes

How would I do that? I honestly don’t really use remote events I tend to avoid them.

2 Likes

Why a remote event when it isn’t needed…

1 Like

Make a remote event somewhere (I’d ideally put it somewhere in replicatedstorage)
On the server, you can fire an event to the client via Remote:FireClient(player, [arguments])
The client can listen to it via Remote.OnClientEvent:Connect(function([arguments])

end)

I’d recommend an argument for whether the player has seated or unseated, and an argument for the vehicle in question so that it can disable the proximity prompts.

1 Like

He’s making client-sided code. Changed will not run as occupant isn’t replicated.

1 Like

Oh, thought he was using a server script…

1 Like

Server Script

Seat:GetPropertyChangedSignal("Occupant"):Connect(function(player)
	if Seat.Occupant then
		ProximityPrompt.Enabled = false
		LockedPrompt.Enabled = false
		game.ReplicatedStorage.HideCarPrompts:FireClient(player)
	else
		ProximityPrompt.Enabled = true
		LockedPrompt.Enabled = true
		game.ReplicatedStorage.ShowCarPrompts:FireClient(player)
	end
end)

Local Script

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Seat = script.Parent

game.ReplicatedStorage.HideCarPrompts.OnClientEvent:Connect(function(player)
	print("Player in Seat")
	script.Parent.Parent.Body.FrontLeft.ProximityPrompt.Enabled = false
	script.Parent.Parent.Body.Left.ProximityPrompt.Enabled = false
	script.Parent.Parent.Body.Right.ProximityPrompt.Enabled = false
end)

game.ReplicatedStorage.ShowCarPrompts.OnClientEvent:Connect(function(player)
	print("Player Left Seat")
	script.Parent.Parent.Body.FrontLeft.ProximityPrompt.Enabled = true
	script.Parent.Parent.Body.Left.ProximityPrompt.Enabled = true
	script.Parent.Parent.Body.Right.ProximityPrompt.Enabled = true
end)

It still won’t run and there is no errors once again

1 Like

First utilise my server script to fire the remote event…

1 Like

It looks like you’re putting a localscript directly in the vehicle. Localscripts won’t work there unless you make them a script with a local run environment (check the properties of a server script)

1 Like

It already works without the .changed

1 Like

There’s no need. :GetPropertyChangedSignal(“Occupant”) is more or less just shorthand of .Changed:Connect(), then checking for whether the property was the one given in the string.

1 Like

Topic says otherwise though…

1 Like

That’s because it’s not being fired because it’s not being replicated. The problem isn’t in :GetPropertyChangedSignal, it’s that the property he’s reading from isn’t replicated.

1 Like

No that was in the local script no the server script

1 Like

I don’t understand a single thing you’ve said in that sentence

If you make a server script and check it’s properties, there’s a runcontext property. Setting this to client will give you a localscript that runs anywhere you put it, while making a regular localscript will give you a script that only works in very few select environments (replicatedfirst, starterplayerscripts, backpack, playergui & your character)

Since you’re putting a localscript directly into your seat, it isn’t parented to any of the environments that a normal localscript would normally run in. You can fix this by doing what I’ve stated above