Hello, I am unknown why this program doesn't work like it is meant to. Basically it checks if a player is in the seat, then allows them to 'press e' (For debugging atm) and only lets them do that if they remain in the seat. However I noticed that it allows it to continue even after the player left the seat.
Anyone got a solution? Much thanks!
local UserInputService = game:GetService("UserInputService")
local Car = game.Workspace.Car
local CarBase = Car.CarBase
local CarMoving = Car.CarMoving
local CarSeat = Car.Seat
local Player = game.Players.LocalPlayer
CarSeat:GetPropertyChangedSignal("Occupant"):Connect(function (humanoid) -- Checking that there is a person in the driver seat
if CarSeat.Occupant then -- Occupant Exists
if CarSeat.Occupant.Parent.Name == script.Parent.Parent.Name then -- Person in the seat is the local player
game:GetService("UserInputService").InputBegan:connect(function(input) -- Input Began checks if the player presses anything and fires whenever the player does so.
if input.KeyCode == Enum.KeyCode.E then -- This detects for a "e" press.
print("E is")
end
end)
end
game:GetService("UserInputService").InputEnded:connect(function(input) -- Fires when input ended
if input.KeyCode == Enum.KeyCode.E then
print("E is no more")
end
end)
else
print(CarSeat.occupant)
end
end)

1 comment
I had to move the stop connections to when the user leaves the seat, but otherwise it works! Thanks!