I have made a function that is supposed to play a song and display a message, stop any music that is playing by stopping the sounds in the SoundScape, (which is where I normally put songs) clone then destroy the script that plays the sounds so that it doesn't play any other songs, and afterwards set the cloned script in the work space so that it can run again. This function is supposed to fire when a specific player joins the server and their character finishes loading.
local music = game.Workspace.Music
local creators = {
"SparkingFruitPunch", "Player2"
}
local already = {}
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function()
for i,v in pairs(creators) do
if v == plr.Name and not already[plr.Name] then
already[plr.Name] = true
local sounds = game.Soundscape:GetChildren()
for i = 1, #sounds do
sounds[i].Playing = false
end
local mc = game.Workspace.Music:Clone()
mc.Parent = game.ServerStorage
music:Destroy()
local nega = Instance.new("Sound", game.Workspace)
nega.SoundId = "rbxassetid://440129799"
nega.TimePosition = 43.00
nega.Volume = 1
nega:Play()
local m = Instance.new("Message", game.Workspace)
m.Text = "The creator, "..plr.Name.." has shown himself upon this day!"
wait(5.30)
m:Destroy()
nega:Destroy()
mc.Parent = game.Workspace
end
end
end)
end)
PLEASE KEEP ALL OF THESE PROBLEMS IN MIND WHEN COMING UP WITH A SOLUTION:
I've recently found out that once a script starts running, you can't simply stop it by disabling it, and this script proves that you can't do it by destroying it either (The variable "music" is pointing to a script). How would I stop a script from running?
On an actual server, the music does not stop playing. This is strange because inside the function is a for loop that goes through every audio file and makes sure that they're not playing.
This is just a hypothesis, but i'm pretty sure if the specified player rejoins the server, this script would error because it has already destroyed the original music script, and the function would ask to destroy it again.
Again, please keep all of these problems in mind when thinking up a solution, because lately people haven't been doing that. (For me at least) Here's the music script if you need it:
local sonic = game.Soundscape.specialStage
local sonicw = sonic.TimeLength
local dbz = game.Soundscape.SoHappy
local dbzw = dbz.TimeLength
local sponge = game.Soundscape.SpongeArcade
local spongew = sponge.TimeLength
local x4 = game.Soundscape.x4
local x4w = x4.TimeLength
while true do
x4:Play()
wait(x4w)
sonic:Play()
wait(sonicw)
sonic:Stop()
wait(5)
dbz:Play()
wait(dbzw)
dbz:Stop()
wait(5)
sponge:Play()
wait(spongew)
sponge:Stop()
wait(5)
end

2 comments
adda
add a debounce that never ends so it will never end at the end :§