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)
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)
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)