Lock and Unlock vehicle with "Seat.Disabled"

This script is used to lock and unlock vehicles using the “L” key regardless of a “template” vehicle, that is, it automatically detects the “Seat” that the player sits in and makes the necessary changes to it for the system to work. What happens is that, when seated, when pressing “L” for the first time the script changes the “Seat.Disabled” property to “true”, preventing the player from entering (it also performs some prints). Once out of the seat, pressing “L” again, the script this time changes “Seat.Disabled” to “false”.

The problem is that even though the property is being changed, I can’t sit down anymore.


-- StarterGUI

-- Serviços
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait(1)
local Humanoid = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Variáveis
local Trancado = false

-- Obtenha ou aguarde a criação do RemoteEvent
local AcessarSeatEvent = ReplicatedStorage:WaitForChild("AcessarSeatEvent")

-- Funções
local function onSeated(isSeated, Seat)
	if isSeated then
		print("O jogador ".. Character.Name .. " sentou em " .. Seat.Name .. "!")
		UIS.InputBegan:Connect(function(input, gameProcessedEvent)
			if input.KeyCode == Enum.KeyCode.L then
				print("O jogador " .. Character.Name .. " clicou L!")
				if Trancado then
					AcessarSeatEvent:FireServer()  -- Chame o evento remoto para destrancar
				else
					wait(0.1)
					Trancado = true
					print("Trancado!")
					Seat.Disabled = true
				end
			end
		end)
	else
		print("O jogador " .. Character.Name .. " não está mais sentado!")
	end
end

Humanoid.Seated:Connect(onSeated)

1 Like

Show the server script too please.