How do I make this happen on the client?

Hello, I’m new to scripting and just made a script for entering and exiting a building. When you enter a building the script will make the wind volume silent, and when you exit it to outside, it will make it loud again.

The issue I’m having is that when someone enters the building, it silences the sound for everyone including the people still outside, I want it to silence only for the person that went inside, but I don’t know how to do that.

I would really appreciate the help!

Heres the script:

script.Parent.Touched:Connect(function(hit)

print("part touched")

game.Workspace.Wind.Volume = 0.4
wait(0.1)
game.Workspace.Wind.Volume = 0.3
wait(0.1)
game.Workspace.Wind.Volume = 0.2
wait(0.1)
game.Workspace.Wind.Volume = 0.1
wait(0.1)
game.Workspace.Wind.Volume = 0

game.Workspace.soundthingy1.Position = Vector3.new(-177.2, 16.55, 809.198)
game.Workspace.soundthingy2.Position = Vector3.new(-177.2, 90.55, 814.597)

end)

you will have to create a localscript, and use the same code, and the localscript should be where the script was.

and I do not recommend you to use basepart.Touched(), it is really unreliable, if someone goes inside the building and resets, the script still thinks it is inside the building, because it never touched the part to get out.

use regions for this, watch this video: https://www.youtube.com/watch?v=L_Jga2MgRdU

3 Likes

Thank you, I didn’t know it was as simple as making a local script with the same code lol.

I tried out the regions too but I’m trying to figure out how to make it get quieter rather than stopping the sound completely

Edit: I figured it out, thank you so much!!

You will need a LocalScript, Still, You should not use Touched, Because, first you’re not adding a debounce, so if the player moves it will run the script

1 Like

Is there a way I could make it choose a random sound when standing in a spot inside the building?

you could use a table of sound ids, and then just choose a random of those, like this:

local tableWithSoundIDs = {12345678, 12345678, 12345678}
local chosenSoundID = tableWithSoundIDs[math.random(1, #tableWithSoundIDs)]

and then you can set the soundid of a sound object to the variable chosenSoundID

1 Like

Where would I implement this into?

in the localscript would work, but if you implement it into a localscript, it will choose random sounds for every player that is in the room.

1 Like