Car horn doesn't work

I’ve been trying to make a horn for my car for over an hour, but it’s not working. I tried to make some prints that didn’t work, and I need help with that.

LocalScript that is activated when the player enters the car:

local UserInputService = game:GetService("UserInputService")
local HornEvent = game.ReplicatedStorage.HornEvent

UserInputService.InputBegan:Connect(function(key)
	if key == Enum.KeyCode.H then 
		local play = "Play"
		print("Fire Server 1")
		HornEvent:FireServer(play)
	end
end)

UserInputService.InputEnded:Connect(function(key)
	if key == Enum.KeyCode.H then 
		local play = "Stop"
		print("Fire server 2")
		HornEvent:FireServer(play)
	end
end)

Script, located at ServerScriptService:

local HornEvent = game.ReplicatedStorage.HornEvent
local HornSound = workspace.Car.VehicleSeat.HornSound

HornEvent.OnServerEvent:Connect(function(play)
	if play == "Play" then
		print("sound played")
		HornSound:Play()
	elseif play == "Stop" then
		print("sound stopped")
		HornSound:Pause()
	end
end)
1 Like

OnServerEvent comes with a first parameter as player. You can try this:

local HornEvent = game.ReplicatedStorage.HornEvent
local HornSound = workspace.Car.VehicleSeat.HornSound

HornEvent.OnServerEvent:Connect(function(_player, play)
	if play == "Play" then
		print("sound played")
		HornSound:Play()
	elseif play == "Stop" then
		print("sound stopped")
		HornSound:Pause()
	end
end)
3 Likes

It’s not working yet, I don’t know why.

Have you tried printing play(parameter) on the server script.

Yes, each one is printed in both scripts and they exist.

Oh didnt notice that, but glad i could help.

1 Like
local HornEvent = game.ReplicatedStorage.HornEvent
local HornSound = workspace.Car.VehicleSeat.HornSound

HornEvent.OnServerEvent:Connect(function(Player, play)
	if play == "Play" then
		print("sound played")
		HornSound:Play()
	elseif play == "Stop" then
		print("sound stopped")
		HornSound:Pause()
	end
end)
1 Like

(reposted from yesterday)

Already figured out the problem:

Replaced for:

if key.KeyCode == Enum.KeyCode.H then

Thank you for your help. I appreciate your availability.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.