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)
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.
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)
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.
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.
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)
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.
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.
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