Help, I'm trying to make a horn system for a car. I'm trying to make it server-sided so all players can hear it. It doesn't work. I have no idea why.
--Server script, parented inside a vehicleseat, which is parented inside a folder inside the truck
--It also has a GUI parented to it.
if script.Parent:IsA("VehicleSeat") then
script.Parent.ChildAdded:Connect(function(child)
if child:IsA("Weld") and game.Players:GetPlayerFromCharacter(child.Part1.Parent)~=nil then
local p=game.Players:GetPlayerFromCharacter(child.Part1.Parent)
local g=script.G:Clone()
g.Parent=p.PlayerGui
g:WaitForChild("SRC_REMOTE1")
g:WaitForChild("SRC_REMOTE2")
g.SRC_REMOTE1.Value=script.Parent.Remote.Horn
g.SRC_REMOTE2.Value=script.Parent.Remote.Horn
g.Horn.Disabled=false
end
end)
end
--Localscript, parented inside the gui.
local mouse=game.Players.LocalPlayer:GetMouse()
script.Parent:WaitForChild("SRC_REMOTE1")
local horngo = script.Parent.SRC_REMOTE1.Value
script.Parent:WaitForChild("SRC_REMOTE2")
local hornend = script.Parent.SRC_REMOTE2.Value
mouse.KeyDown:connect(function(key)
if key=="h" then
horngo:FireServer()
end
end)
mouse.KeyUp:connect(function(key)
if key=="h" then
hornend:FireServer()
end
end)
horngo.Parent.Parent.ChildRemoved:connect(function(child)
if child.Name=="SeatWeld" then
hornend:FireServer()
script.Parent:Destroy()
end
end)
--Serverscript parented inside the folder, which controls the remoteevent.
local remote = script.Parent.Remote.Horn
while wait() do
remote.OnServerEvent:Connect(function()
local truck = script.Parent.Parent
truck:SetAttribute("Horn", true)
end)
end

7 comments
There is alot of stuff wrong in this script
I would also make it a localscript sending a remote which fire all clients (and ignore the sender), so it will horn immediately with no delay
Ecactly as above said, you need to fire a server, you can just try mame it heard using server scrilt that runs when the hor button is pressed or when the event is fired
@sayer80 What exactly is wrong? I know I'm using Mouse.Keydown, that's because it's an old script that I used for reference. But how do I fire all clients?
I changed the directory of the remote in the serverscript, now it works! Now I need to replace the Mouse.KeyDown event.s
Instead of doing :GetMouse method, use UserInputService.
Yes, when I said "replace the Mouse.KeyDown events" I was implying that I was going to replace them with UserInputService.