Lately, I’ve been trying to make sounds play for the client only, and not for the server, but I cannot seem to do it.
What do you want to achieve? I want sounds to play only for the client, and not the server.
What is the issue? Whatever I do, it doesn’t work as intended.
What solutions have you tried so far? I searched for similar posts, and looked at the Developer Hub, but I didn’t see my answer.
I also have tried setting SoundService.RespectFilteringEnabled to true, but everytime, the result was either it was playing for the entire server, or no sound played at all. Any help is appreciated.
Edit: The sound is supposed to play when a part is touched.
Double Edit: Here is the script that plays the sound.
local debounce = false
game.Workspace.BadRamp4.Touched:Connect(function(hit) --Change bad part name
if not debounce then
debounce = true
print("Oof!")
game.Workspace.BadRamp4.Material = Enum.Material.Neon --Change bad part name
game.Workspace.Whoops:Play()
wait(1)
game.Workspace.BadRamp4.Material = Enum.Material.SmoothPlastic --Change bad part name
debounce = false
end
end)
What about if you parent the sound into a player and play it from player? but I am pretty sure it should work only for clients if you call play from localscript.
script inside part:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.RemoteEvent:FireClient()
end
end)
Sound and parent of it is this localscript in StarterGui:
Try this - Creating the sound inside CurrentCamera, setting the SoundId and then playing it.
local camera = workspace.CurrentCamera
-- Creating Sound --
local sound = Instance.new("Sound")
sound.Parent = camera
sound.SoundId = "blah"
sound:Play()
local services = setmetatable({},{
__index = function(self,key)
return game.GetService(game,key) or nil
end
})
local soundservice = services.SoundService
local id = 49584959 -- insert id here
soundservice:PlayLocalSound(id)
this script should work on the client, if you wanted to make it into a client even you could also convert that
About two years ago I used to keep all my local sounds in StarterGui, however an update in 2017-18 made it so that sounds could not be heard in StarterGui; I am unsure if this was ever fixed.
Ah. Now I’m convinced I understand what the problem is.
There’s no code provided, but I’m going to go ahead and assume you’re either not handling this interaction from a LocalScript or you aren’t checking if the player who touched the part is the LocalPlayer, which causes the supposed “sound playback replication” issue you’re experiencing.
Sorry, I’ll provide some code. It is indeed in a LocalScript.
local debounce = false
game.Workspace.BadRamp4.Touched:Connect(function(hit) --Change bad part name
if not debounce then
debounce = true
print("Oof!")
game.Workspace.BadRamp4.Material = Enum.Material.Neon --Change bad part name
game.Workspace.Whoops:Play()
wait(1)
game.Workspace.BadRamp4.Material = Enum.Material.SmoothPlastic --Change bad part name
debounce = false
end
end)
The script works as intended, but the sound just isn’t client sided.
local debounce = false
local sound = game.Workspace.Whoops:Clone()
sound.Name = "Whoops"
sound.Parent = game.Players.LocalPlayer
game.Workspace.BadRamp4.Touched:Connect(function(hit) --Change bad part name
if hit.Parent:FindFirstChild("Humanoid") then
if not debounce then
debounce = true
print("Oof!")
game.Workspace.BadRamp4.Material = Enum.Material.Neon --Change bad part name
game.Players:FindFirstChild(tostring(hit.Parent)):FindFirstChild("Whoops"):Play()
wait(1)
game.Workspace.BadRamp4.Material = Enum.Material.SmoothPlastic --Change bad part name
debounce = false
end
end
end)
Refer to the post I put up. You will need to check if the part that touched your detector is a descendant of the character and run this from a LocalScript.
@ArticGamerTV Checking for the presence of a Humanoid or changing the location of the sound is not sufficient enough. You will still experience global playback if you do not explicitly check who touches the detector.
Easy way of going about it:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
game.Workspace.BadRamp4.Touched:Connect(function(hit) --Change bad part name
-- Change starts here and ends off next line
local player = Players:GetPlayerFromCharacter(hit.Parent)
if (player and player == LocalPlayer) and not debounce then
debounce = true
print("Oof!")
game.Workspace.BadRamp4.Material = Enum.Material.Neon --Change bad part name
game.Workspace.Whoops:Play()
wait(1)
game.Workspace.BadRamp4.Material = Enum.Material.SmoothPlastic --Change bad part name
debounce = false
end
end)
Remember: LocalScript. Preferably in StarterPlayerScripts. Use of WaitForChild may be necessary in some cases; try reducing redundancy as well, for example, by assigning BadRamp4 to a variable.