Well, you're on the right track. However your mistake is that you're running this code as soon as the server starts, and it only runs once. To run only when a player sits in a seat we're going to want to run the :GetPropertyChangedSignal()
method on the seat and listen for the Occupant property.
1 | local Seat = script.Parent |
3 | Seat:GetPropertyChangedSignal( "Occupant" ):Connect( function () |
This code will run whenever somebody sits or leaves the specific seat.
Now of course we will want to check which of those it is, and play the sound depending on whether they sat down or left the seat.
01 | local Seat = script.Parent |
02 | local SoundOne = script.Parent:WaitForChild( "Sits" ) |
03 | local SoundTwo = script.Parent:WaitForChild( "Unsits" ) |
05 | Seat:GetPropertyChangedSignal( "Occupant" ):Connect( function () |
06 | if Seat.Occupant ~ = nil then |
I hope this helped. You should take a look at this link to better understand the use of this method for future reference.
If I did help, then please mark my answer as accepted or reply to this answer if you need further help!