Hi there! Not too sure on where to put this in the devforum, but I’m really stuck here! I have a game that is similar to obby games that can be selected by players. When the player selects the map with the highest amount of votes, the map will spawn and then teleport the player. There is even custom music playing throughout the course!
However, I am at a bit of a pickle here…
Every time that I try to test it out, I hear the music playing despite the map not being visible! It is located within ReplicatedStorage with the map.
For the setup, I am running scripts in the ServerScriptService for the map selection, alongside with having a voting system too.
This is what I have to make the music run within the map.
And these are the properties of the sound within the part.
However, every time that I end up play-testing the game, I ALWAYS hear the music playing despite it being in the map, AND in replicated storage!
Do you guys know what to do to fix this? Or is this non fixable? I’ve tried everything I could, involving YouTube searches, as well as trying to find something similar in the devforum! I could workaround for this by just having the maps in separate areas, but I’m hoping there’s a way to make it easier.
Help is appreciated!
You could try to set the sound.playing to false while it is in the Replicated Storage then when it is moved to the workspace make the sound play.
Code sample 1
local Sound = --Put in-game sound object here
local Map = --Put in-game map here
local function SoundCheck()
if Map:FindFirstAncestor("ReplicatedStorage") then
Sound.Playing = false
elseif Map:FindFirstAncestor("Workspace") then
Sound.Playing = true
end
end
spawn(SoundCheck)
This is somewhat inefficient though because of the while loop.
Code Sample 2
local Maps = {} -- Put all maps in table separated by ",".
local Sounds = {} -- Put all corresponding sounds in table separated by ","
for i, v in ipairs(Maps) do
if v and v:IsA("Model") then
v.AncestryChanged:Connect(function()
local TableNumber = i
if v:FindFirstAncestor("ReplicatedStorage") then
Sounds[TableNumber].Playing = false
elseif v:FindFirstAncestor("ReplicatedStorage") then
Sounds[TableNumber].Playing = true
end
end)
end
end
Neither of these code sample are the greatest. I am not a great scripter.