Need help with horn on vehicleseat that can hear player near me

Hello,
I tried to ask at scriptinghelpers.org, I didn’t get an answer.
I want help with this:
How can I make a horn in the vehicleseat that when you press a “H” key, it will make a sound and players near me will hear a sound.

I tried all the tutorials I found on devforum or on youtube, but none of them worked.

FilteringEnabled is enabled so I dont know where is the problem.

3 Likes

If only you can hear the sound, ur probably using a local script, if that’s the case then use a normal script, otherwise I’m not sure.

1 Like

I know its the problem of local script but with normal script didnt work.

1 Like

Use RemoteEvent, the local will detect when you press H and the server will play the sound that should be inside a part.

1 Like

I am not expert in scripting but I try it.

1 Like

Local Script:

local UserInputService = game:GetService("UserInputService")

local player = game.Players.LocalPlayer
local character = player.Character
local HumanoidRootPart = character.HumanoidRootPart

local seat = workspace.Car.VehicleSeat -- Change this to your vehicle seat

local RE = game.ReplicatedStorage.RemoteEvent

local function onInputBegan(input, gameProcessed)
	if not gameProcessed and input.KeyCode == Enum.KeyCode.H then
		if (HumanoidRootPart.Position - seat.Position).Magnitude < 20 then
			RE:FireServer()
		end
	end
end
 
UserInputService.InputBegan:Connect(onInputBegan)

Server Script:

local seat = workspace.Car.VehicleSeat -- Change this to your vehicle seat

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
	seat.HonkSound:Play() -- Change this to your honk sound
end)

Try this, it uses remote events.

6 Likes

Where must be server script? I placed to ServerScriptService and it didnt work.

Did you put a RemoteEvent in ReplicatedStorage?

1 Like

Yes. I renamed it to RemoteEventpiskat and renamed in scripts the name of RemoteEvent.

Put the local script in StarterCharacterScripts and the Server Script in ServerScriptService

1 Like

It works! I’ll try it with friends and I tell you if it works.

@3LettrName It fully works! Thank you so much for scripts!

Hey thnx mahn for helping me figure out about the horn in a car :slight_smile: