How To Make A Horn System

I am making a game, and I want to make it so that when someone is in the vehicle seat and presses H, the horn sound will play. I have tried many different ways and can’t do it. Does anyone know a way I can do it?

Check this out, and search up other posts about UserInputService.

There’s a code example on the wiki that’s pretty much what you’re asking for

https://developer.roblox.com/en-us/api-reference/function/ContextActionService/BindAction

Hi! It’s very simple to make.

Just do a Server Script that detects if a player seated
Like this:

local seat = script.Parent

seat.ChildAdded:Connect(function(child)
       if child.Name == "SeatWeld" then
             local player = game:GetService("Players"):GetPlayerFromCharacter(child.Part1.Parent)
             if player ~= nil then

            end
       end
end)

seat.ChildRemoved:Connect(function(child)
       if child.Name == "SeatWeld" then
             local player = game:GetService("Players"):GetPlayerFromCharacter(child.Part1.Parent)
             if player ~= nil then

            end
       end
end)

and search for binding actions for the Keys.

Maybe when a player presses a key a remote event fires and you can put a script inside the seat that when it fires it checks if the occupant is the player, if it is, then it plays the horn

I have done this, but it doesn’t work. How would I do it?

local seat = script.Parent
local UserInputService = game:GetService("UserInputService")

seat.ChildAdded:Connect(function(child)
	if child.Name == "SeatWeld" then
		local player = game:GetService("Players"):GetPlayerFromCharacter(child.Part1.Parent)
		if player ~= nil then

		end
	end
end)

local function onInputBegan(input, _gameProcessed)
	if input.KeyCode == Enum.KeyCode.H then
		script.Parent.Horn:Play()
	end
end
UserInputService.InputBegan:Connect(onInputBegan)

seat.ChildRemoved:Connect(function(child)
	if child.Name == "SeatWeld" then
		local player = game:GetService("Players"):GetPlayerFromCharacter(child.Part1.Parent)
		if player ~= nil then

		end
	end
end)

UserInputService is only Client Side that’s means that you can only run on LocalClient Scripts.

Create a script that detect’s if the key is pressed, and send a RemoteEvent to the Server Script and all the checks needed to be sure that the player is seated!

Try this out:
Why Does This Script Not Work? - Help and Feedback / Scripting Support - DevForum | Roblox