Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to enable a sound effect that only happens locally?

Asked by 5 years ago

So right now I have two bricks. One is indoors that contains this script and another is outdoors that contains this script, except that one is set to false.

script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
game.StarterGui.Music.EqualizerSoundEffect.Enabled = true
game.StarterGui.Rain.EqualizerSoundEffect.Enabled = true
end
end)

First of all, my goal is to enable the EqualizerSoundEffect that is under 2 sounds named "Music" and "Rain" which are currently placed under PlayerGui (I already have a local script under the PlayerGui that plays the music by the way).

BUT

My problem: The script just doesn't work and when I just have both of the sounds placed under Workspace and have it enabled from there, the EqualizerSoundEffect is enabled for everyone in the game, but I only want it to be enabled for the person entering a room.

I'm hoping someone can help me clear this up because I don't want to have to make my game single player just because I can't get a simple sound effect to only happen locally. Thanks.

0
The sound is playing server sided, correct? User#24403 69 — 5y
0
Alright LeSatan 0 — 5y
0
if you call the sounds from a local script they will play locally Rubenske1 89 — 5y

2 answers

Log in to vote
0
Answered by
angeI1001 123
5 years ago

You can do it by using a localscript.

Hope I helped.

0
so helpful tictac67 96 — 5y
Ad
Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
5 years ago

Server script:

local RemoteEvent = game.ReplicatedStorage:WaitForChild("NameOfRemote") -- place a remote event in ReplicatedStorage

local RainAudio = game.StarterGui.Rain
local MusicAudio = game.StarterGui.Music

script.Parent.Touched:connect(function(part)
    local parentModel = part.Parent
    local humanoid = parentModel:FindFirstChildOfClass("Humanoid")
    if humanoid then 
        -- verify if it's a player not a npc
        if game.Players:FindFirstChild(parentModel.Name) then -- parentModel = Character
            RemoteEvent:FireClient(RainAudio, MusicAudio) -- send the sounds you want the local script to change
        end
    end
end)

Local script:

local RemoteEvent = game.ReplicatedStorage:WaitForChild("NameOfRemote") -- make sure this is the exact remote the server script is using

RemoteEvent.OnClientEvent:Connect(function(rainAudio, musicAudio)
    rainAudio.EqualizerSoundEffect.Enabled = true 
    musicAudio.EqualizerSoundEffect.Enabled = true 
end)

Answer this question