Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to enable a sound effect that only happens locally?

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.

3 comments

0

The sound is playing server sided, correct?

0

Alright

0

if you call the sounds from a local script they will play locally

2 answers

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.