Hello, I am struggling with this, I am trying to make a game that will involve vehicles that can perform functions when the player in the driver seat presses buttons. For example, if the driver was to press L, it would run a function like this to turn the lights on.
local toggle = 0
function lightsOn()
if toggle == 0 then
toggle = 1
lights.Material = "Neon"
lights.Spotlights.Enabled = true --Yes i know lights.Spotlights wont work, its just metaphorical
elseif toggle == 1 then
toggle = 0
Lights.Material = "Plastic"
lights.Spotlights.Enabled = false
end
end
But I cant find any way of detecting the player pressing a button only if they are on the seat. I always hit a brick wall, I have tried accessing the player through the seat weld then discovering you can only use Player.GetMouse() in local scripts, I have also tried reverse engineering plane seats because they use P for full speed only to remember they use a tool. I really don't want the player to have to use a tool while in the seat because they will be using other tools while driving. all i'm looking for is a way to be able to make any button on the keyboard do something as if you were clicking a part using the ClickDetector. I would like multiple buttons per vehicle and also there will be many vehicles so I don't want any of the vehicles interfering with each other. If anyone can help I will be very grateful.

9 comments
I appreciate your help but I can't seem to get the script to work. where it said --do thing I put print("Pressed") for testing. When I clicked run, i got an error line 20:"attempt to index nil with 'InputBegan'", After changing the UserInputService on line 20 to UIS the error went away but it still doesn't work
Ah, sorry. I confused the variable names. I'll change my answer to solve the errors. What are the errors after changing the variable name to UIS?
Keep in mind UserInputService only worked on LocalScripts
After changing the the variable to UIS, I got nothing at all but it wasnt working, I spotted a missing set of brackets on line 20 "UIS.InputBegan:connect(lightsOn())" those two after lightsOn were missing, after changing that I now have an error saying "Workspace.VehicleSeat.Script:6: attempt to index nil with 'UserInputType'" I also tried it in a localscript and no luck
What happened when you tried it in a localscript? You don't need to add a set of brackets if you're making connecting an event to a seperate function.
Whe I tried it in a localscript, it did the same thing as before. Adding brackets also made the function run, without them it just stopped at UIS.InputBegan:connect(lightsOn()). I have been experimenting with your new script and havent got any results from it, just a missing bracket to close line 5 that I put after the last end on line 20, still doesnt work though
Also, apparently LocalScripts only run if they are inside the player like in backpack, playersripts or playergui etc. Mabye theres a way to do it by checking what player sat on the seat and then cloning a local script into backpack or (PlayerScripts isnt accessable by the server) and removing it when the player guts up?
Alright, looks like I'm stuck here then. Looks like you're on your own then. Sorry for the inconvinience. You don't have to clone it though.
Ok no worries, thanks for trying. I think the main problem at the moment is that pressing a key isnt triggering UIS.InputBegan:connect()