I have this code:
local Plr = game.Players.LocalPlayer function onKeyPress(inputObject, gameProcessedEvent) if script.Parent.Occupant.inputObject.KeyCode == Enum.KeyCode.E then game.ReplicatedStorage.notification:FireClient(Plr, "test!") end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
but when I sit in the seat and press E, nothing happens, please help.
Extra info:It's an anchor system for a ferry kit, so I'm going to have a notification system that shows up on the person in the seat's screen.
This is supposed to be a LocalScript since you're using Players.LocalPlayer
, which in this case, you can have the notification fire locally without having to use RemoteEvents.
If you want to fire the server for some reason, use ReplicatedStorage.notification:FireServer(argument)
.
local plr = game:GetService('Players').LocalPlayer repeat wait() until plr and plr.Character and plr.Character:FindFirstChild('Humanoid') local char,hum = plr.Character,plr.Character.Humanoid local UIS = game:GetService('UserInputService') local ReplicatedStorage = game:GetService('ReplicatedStorage') UIS.InputBegan:Connect(function(input,event) if input.KeyCode == Enum.KeyCode.E and hum.Sit == true then if hum.SeatPart ~= nil and hum.SeatPart.Name == 'SomeSeatName' then print('you're sitting on a specific seat!") --this returns the Part itself, so you can check if it's a specific color or such end --not sure what you're doing here, but you can't fire client from a local script --make this notification happen on the client instead of through an event print("you're sitting and pressing a key!") end end)
Instead of using onkeypress try using a
kayDown()
function