Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to tell if the occupant of a seat is pressing a key?

Asked by 4 years ago

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.

2 answers

Log in to vote
1
Answered by
Mayk728 855 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
This works in every seat, so anybody can anchor the ship if they're sitting in a seat, is there a way to edit this so that if they're sitting in a specific seat, and only a specific seat it works? VoidKeyword 111 — 4y
0
i made an edit Mayk728 855 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Instead of using onkeypress try using a

kayDown()

function

0
I don't think this makes a difference, I tried and nothing happened. VoidKeyword 111 — 4y

Answer this question