@Reset4319806 (Triangle) posted a new topic, subject "Vehicle Seat Occupant only keys?". It read:

   I am trying to make a boat for my game. i have all of the main controls (forward, left, right, backwards) in a global script but i also need to make some extra keys for things such as anchor. how would this be done?
    
    i have made a localscript inside the seat but when i check for the occupant with
    [code] 
        script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
            if script.Parent.Occupant == game.Players.LocalPlayer.Character.Humanoid then
        	    print("test")
            end
        end)
        
    [/code]
    
    it doesn't work.  
    what should i do?

After which, @TOP_Crundee123 (PoopAtLightSpeed) added

    You should use a remote event. Local scripts don't affect the server.

After which, @Romeo_Duncan (Romeo_Duncan) added

    Try using this instead:
    [code] 
        local Player = game.Players.LocalPlayer
        local Character = Player.Character or Player.CharacterAdded:Wait()--ensuring character is loaded in
        script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function(Humanoid)
            if Humanoid and Humanoid.Parent == Character then
                --do stuff
            end
        end)
        
    [/code]

So @Reset4319806 (Triangle) replied

    did i ever say i wasn't going to use remote events?
    
    and @Romeo_Duncan that didn't work. ill see if it if getting the signal

After which, @Reset4319806 (Triangle) added

    it isn't getting the signal for the humanoid either

@Romeo_Duncan (Romeo_Duncan) replied

    ensure the scripts parent is the seat and not the boat model

Then @Reset4319806 (Triangle) said

    it is inside of the seat as it has been the entire time, still nothing

After which, @Romeo_Duncan (Romeo_Duncan) added

    Well there is nothing wrong with the script i give you did you try checking if the signal fires? try printing a message

@TOP_Crundee123 (PoopAtLightSpeed) replied

    I'm sorry, try using his script but without the humanoid, just include the humanoid.character part

@Reset4319806 (Triangle) replied

    it isn't firing @Romeo_Duncan idk what is wrong with it

To which @Romeo_Duncan (Romeo_Duncan) replied

    ill test it out in studio now and get back to u

After which, @Romeo_Duncan (Romeo_Duncan) added

    I just read on devhub that this property doesnt replicate so the change will only be detected from a server script so you have to do this code from the server,alternatively you can detect when the local player is sitting and check if the seat is equal to the vehicle seat like this:
    [code] 
        local Player = game.Player.LocalPlayer
        local Seat = script.Parent
        local Character = Player.Character or Player.CharacterAdded:Wait()
        local Humanoid = Character:WaitForChild("Humanoid")
        --this function fires when the player sits or gets up
        Humanoid.Seated:Connect(function(isSeated,seat)
              if isSeated and seat == Seat then
              --player is seated in boat
              end
        end)
        
    [/code]

@Reset4319806 (Triangle) replied

    ah, ok. i will test this out and give you the feedback in a bit

Then @Reset4319806 (Triangle) said

    it still isnt detecting it. i am going to try making it `humanoid.Changed:Connect()`
    
    edit: nope

After which, @Reset4319806 (Triangle) added

    fixed it. only problem is. my camera is messed up when i get out of the seat
    [code] 
        local Player = game.Players.LocalPlayer
        local Character = Player.CharacterAdded:Wait()
        local Humanoid = Character:WaitForChild("Humanoid")
        
        Humanoid.Seated:Connect(function(seated, seat)
        if seated then
        	local SeatParent = seat.Parent
        	if seat.Name == "BoatSeat" then
        		game:GetService("RunService").RenderStepped:Connect(function()
        			if Humanoid.Seated then
        				if seat.Name == "BoatSeat" then
        					workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
        					workspace.CurrentCamera.CFrame = SeatParent.Camera.CFrame
        				elseif not seat.Name == "BoatSeat" then
        					workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
        					workspace.CurrentCamera.CFrame = Character.Head.CFrame
        				end
        			else
        				workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
        				workspace.CurrentCamera.CFrame = Character.Head.CFrame
            			end
            		end)
            	end
            end
        end)
    [/code]

Then @colbert2677 (colbert2677) said

    The way you're handling the camera is incorrect. Leave the camera setting to the default camera control module. Using a CameraType of Scriptable will automatically stop it from placing the camera in its intended place. You only need to update the Camera CFrame while the player is in the boat.
    
    Something else: I think it would do you justice to use BindToRenderStep in this case so you can quickly bind and unbind the camera setting function. In your case, you spawn up a new connection to RenderStepped every time a player sits. That's going to be _really bad_ in the long run.
    
    I've made a couple other improvements to your original code, such as removing unnecessary and redundant chunks. There are other improvements to be made (such as not assuming non-nils for your variables), but that's something to fill out on your own time.
    [code] 
        -- Remember: if this is in StarterPlayerScripts, you need to account for
        -- respawns by updating variables upon respawn.
        local RunService = game:GetService("RunService")
        local Player = game:GetService("Players").LocalPlayer
        local Character = Player.Character or Player.CharacterAdded:Wait()
        local Humanoid = Character:WaitForChild("Humanoid")
        local Camera = workspace.CurrentCamera
        
        Humanoid.Seated:Connect(function (seated, seat)
            if seated and seat.Name == "BoatSeat" then
                local seatParent = seat.Parent
                Camera.CameraType = Enum.CameraType.Scriptable
                RunService:BindToRenderStep("BoatCamera", Enum.RenderPriority.Camera.Value, function()
                    Camera.CFrame = seatParent.CFrame
                end)
            else
                -- Let camera module take over: do not set CFrame yourself
                Camera.CameraType = Enum.CameraType.Custom
                -- May have to do better handling regarding this bit, I just put this here as a catch-all case
                RunService:UnbindFromRenderStep("BoatCamera")
            end
        end)
        
    [/code]

After which, @Romeo_Duncan (Romeo_Duncan) added

    Adding to what @colbert2677 you can try saving the Cframe of the camera before you alter it like this:, I am not certain if this will work but you can give it try
    [code] 
        local RunService = game:GetService("RunService")
        local Player = game:GetService("Players").LocalPlayer
        local Character = Player.Character or Player.CharacterAdded:Wait()
        local Humanoid = Character:WaitForChild("Humanoid")
        local Camera = workspace.CurrentCamera
        local LastCFrame = nil
        
        Humanoid.Seated:Connect(function (seated, seat)
            if seated and seat.Name == "BoatSeat" then
                local seatParent = seat.Parent
                LastCFrame = Camera.CFrame
                Camera.CameraType = Enum.CameraType.Scriptable
                RunService:BindToRenderStep("BoatCamera", Enum.RenderPriority.Camera.Value, function()
                    Camera.CFrame = seatParent.CFrame
                end)
            else
               if LastCFrame then
                  Camera.CFrame = LastCFrame
                  LastCFrame = nil
               end
               Camera.CameraType = Enum.CameraType.Custom
               RunService:UnbindFromRenderStep("BoatCamera")
            end
        end)
        
    [/code]


{'source': 'discourse', 'url': 'https://devforum.roblox.com/t/vehicle-seat-occupant-only-keys/376096', 'title': 'Vehicle Seat Occupant only keys?', 'views': 1192, 'has_accepted_answer': False, 'word_count': 980, 'like_count': 8, 'reply_count': 12, 'participant_count': 4, 'posts': 17, 'tags': '', 'author': '@Reset4319806 (Triangle)', 'participants': '@Reset4319806 (Triangle), @TOP_Crundee123 (PoopAtLightSpeed), @Romeo_Duncan (Romeo_Duncan), @colbert2677 (colbert2677)', 'image_url': [None], 'created_at': '2019-10-26T18:14:03.380Z', 'last_posted_at': '2019-10-27T00:17:46.134Z'}