How to set a max sound distance?

Hi, I have a horn system i got working, but i can hear the horn everywhere in my game. And yes it is audible for other players. I have the horn in the workspace. In the ui there is a horn button where the car controls are, I have a script (in horn button) that has this
code: local horn = workspace.Horn–My horn name

script.Parent.MouseButton1Down:Connect(function()
horn:Play()
end)
I have tried setting a max distance in the horn sound and it does nothing.
This is the devforum post I used to get my horn audible: How to make this car horn audible to other players? - #15 by RMofSBI
Pictures of the explorer tab


If possible can you show me the code to do this, im still learning

2 Likes

If the Sound instance isn’t parented to a BasePart or an Attachment, it’s considered “global” and has the same volume everywhere in the game. You need to parent it to a part within the car for it to have the desired effect.

3 Likes

I put the horn in a part in the car as soon as i did that, the horn wouldn’t work. So changed the script. Instead of workspace I changed it to thepartname and still nothing i don’t think i did it right. What should I change in the script? Or placement of the part?

1 Like

did you format it like this?

local horn = workspace["2002 Honda Van"].*thepartparent*.*thepartname*.*YourSoundHere*

and not

local horn = *thepartname*.*YourSoundHere*
1 Like

Hi, I tried how you did it but the bracket keeps getting underlined in red. I still tested it and the horn made no sound.

Hey :slight_smile: You Need to change the Honda Van Name because it Beginns with a Number and you have an Underscore! You need to change the Van example „HondaVan“ and then it Should work!

1 Like

Change the Van Name and the Script should be like this :

local horn = game.Workspace.HondaVan.Body.HornPart.Horn1

2 Likes

It Works!! Thank You XD

[MSG Must Be 3O Characters long So here extra letters]

1 Like

Happy to Help :slight_smile:

Greetings
Aim

1 Like

Hi, your solution works, but it doesn’t work with my car spawner. How can I get the horn to work with my spawner? What is happening is the car spawner clones the car, but when i honk the horn in that car and someone else is using the same car the horn would only work in one of them.

1 Like

Hmm I think I have a fix for that.

So put an Script in the Vehicle in the Horn and use this Script down there!

Important is that you maybe should change the Parents because I don’t know how many Thinks are in the Group so just when It don’t work and gives an Error Than just remove an Parent or give an Parent

script.Parent.Parent.Horn1
1 Like

I tried it, it just kept under lining the whole thing red. I even added and got rid of the parents on that script. My car is in severstorage in a folder called ShopCars when I spawn it, it clones it to workspace, it works fine unless if there are 2 of the same car spawned in it would only work on 1 of them.

1 Like

It can be more Parents then it can be working till 8 but I think the Script should be working Remember you write

Parent

Not

Parents
2 Likes

But one Tip

Remove the Horn1 and add the Parents and make an Point and do H and when it don’t Pop up the Horn1 then remove the H and add and Parent again till It pop ups

2 Likes

I created a script in horn sound that said script.Parent.Parent.Horn and it keeps underlining it. What I did first is script.Parent then i did h, nothing happened so i put parent again and then allowed me to put Horn1. Still won’t work for both Hondas’

1 Like

Can you show me the Script please?

Of course!
Screen Shot 2022-08-24 at 8.19.50 PM

Ohhhh my Bad you don’t wrote the Script fully so just set the Script in the Horn Part and try the Script again with the Parents and the Script should be the The same like this

local horn = script.Parent.Parent.Parent.HornPart.Horn1 — Check the Parents

script.Parent.MouseButton1Down:Connect(function()

horn:Play()

end)

I hope this Helps :slight_smile:

1 Like

It didn’t do anything, I’m still having the same problem :roll_eyes:
I tried it with 3 .Parent and 2 .Parent.
Screen Shot 2022-08-25 at 7.58.56 AM

Did it show the Pop Up?

When you want to Spawn the Other Vehicle show me the Output