So I’m having this issue where whenever a player joins the game this looping sound duplicates, the thing is that it’s only supposed to do this once upon the first player joining the game and never again after that.
local Players = game:GetService("Players") --Get the players.
local wind = script.Parent.background_wind_noise.soft_mid_wind_00 --Get the sounds (Feel free to change the path to the sound as well).
function background_wind () --Feel free to change this.
local sfx = wind:Clone() --Clone the sound.
sfx.Parent = workspace --Move it to the workspace.
sfx:Play() --Play it!
end
Players.PlayerAdded:Connect(function() --Wait until the player or players connect.
background_wind() --Go to this function!
end)```
local Players = game:GetService("Players") --Get the players.
local wind = script.Parent.background_wind_noise.soft_mid_wind_00 --Get the sounds (Feel free to change the path to the sound as well).
function background_wind () --Feel free to change this.
if not workspace:FindFirstChild("Sound") then
local sfx = wind:Clone() --Clone the sound.
sfx.Parent = workspace --Move it to the workspace.
sfx:Play() --Play it!
end
end
Players.PlayerAdded:Connect(function() --Wait until the player or players connect.
background_wind() --Go to this function!
end)
Also that’s not needed just enable the “Playing” value in the sound and whenever someone joins itll just play and wont affect when any others join
There is a very simple solution to this.
Make a local script in StarterPlayerScripts with this code in it:
task.wait(.5)
game.YourPathHere:Play()
So every time someone joins the game, the player here’s whatever sound you want to play. If you would like for everyone to hear this sound, just copy and paste the code into a server script in ServerScriptService.
why not just have the sound already in the workspace?
and/or just play it from the client side?
but if you want to use your script this is easy fix it in just return if the sound is already in workspace
local Players = game:GetService("Players") --Get the players.
local wind = script.Parent.background_wind_noise.soft_mid_wind_00 --Get the sounds (Feel free to change the path to the sound as well).
function background_wind () --Feel free to change this.
if workspace:FindFirstChild(wind.Name) then return end -- its already there and playing so return
local sfx = wind:Clone() --Clone the sound.
sfx.Parent = workspace --Move it to the workspace.
sfx:Play() --Play it!
end
Players.PlayerAdded:Connect(function() --Wait until the player or players connect.
background_wind() --Go to this function!
end)
That seems to work, thank you! To answer your question as to why I’m coding this the way I am, it’s because sooner or later they’ll be multiple sounds playing at random times in certain parts. And instead of having a script in each part I thought it’d be easier to organize it all into one script.