Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Vehicle keyboard input script does not work. How do I fix it?

Alright, so I made a LocalScript where if someone's in a VehicleSeat and the key "P" is pressed, a brick in the Workspace will turn Blue. My script won't work though, nothing shows up in the Output or Script Analysis. Can someone please fix it? Thank you in advance.

-NightlyBasis

local uis = game:GetService("UserInputService")

script.Parent:WaitForChild("Humanoid").Changed:connect(function()
    if script.Parent.Humanoid.SeatPart ~= nil then
       uis.InputChanged:connect(function(input)
            if input.KeyCode == Enum.KeyCode.P then
                game.Workspace.BlueEvent:FireServer()
            end
        end)
    end
end)

1 answer

✓ Accepted answer

###You could instead check if the humanoid has a seat part when you press the key. You should also place remotes in ReplicatedStorage, for easy client-server access.

local uis = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

uis.InputBegan:Connect(function(input) -- use InputBegan
    if input.KeyCode == Enum.KeyCode.P and hum.SeatPart then -- no need for ~= nil
        game.ReplicatedStorage.BlueEvent:FireServer()
    end
end)

###On a side note, :connect() is deprecated, use :Connect() instead

7 comments

0

I put the script in, and moved events to ReplicatedStorage, nothing happens.

0

Sorry for being a bit broad, make sure this is a LocalScript in StarterGui, StarterPack, or PlayerScripts

0

Is there a way to put it inside the VehicleSeat? This is because I'll use the inputs for functions within the car (E.G. Q is for left indicator).

0

No, it will not run under it.

0

Is there a way to make it run as a child of VehicleSeat?

0

Nope.

0

Alright, thanks for your help though

This discussion is preserved as it was. New answers, comments, and votes are closed.