How to start Music always at TimePosition 0?

Hello, :wave:

I want to create a script where music is played automatically and always starts at 0.
But how do you make it that the music always starts at TimePosition 0? :thinking:
I’ve tried several things but they didn’t work.

This is the script I already have

local songs = 
	{1532584532,
		836718931}

while true do
	
	local music = game.ReplicatedStorage.CurrentMusic
	
	local ID = songs[math.random(1,#songs)]
	music.SoundId = "rbxassetid://"..ID
	music:Play()
	music.Ended:Wait()
	
	music:Destroy()
end

You’re destroying the Sound instance which could be related to your issue? Try this?

local songs = 
	{1532584532,
		836718931}

local music = game.ReplicatedStorage.CurrentMusic

while true do
	local ID = songs[math.random(1,#songs)]
	music.SoundId = "rbxassetid://"..ID
	music.TimePosition = 0
	music:Play()
	music.Ended:Wait()
end
2 Likes

I don’t think it worked
fjfjfjhd

Is your Sound instance looped?

No, should it be looped? :expressionless:

Try this?

local songs = 
	{1532584532,
		836718931}

local music = game.ReplicatedStorage.CurrentMusic

while true do
	local ID = songs[math.random(1,#songs)]
	music.SoundId = "rbxassetid://"..ID
	music:Play()
	music.Ended:Wait()
	music:Stop()
end

Stop() should it back to 0

Now it only plays once and stops and doesn’t start at 0

Odd? Could it maybe you have to clone the sound instance? Is this a local script?

It’s a normal script and what do you mean with clone the sound instance? Sorry I’m just a beginner

Something like this?

ocal songs = 
	{1532584532,
		836718931}

local music = game.ReplicatedStorage.CurrentMusic

while true do
	local clone = music:Clone()
	local ID = songs[math.random(1,#songs)]
	clone.SoundId = "rbxassetid://"..ID
	clone:Play()
	clone.Ended:Wait()
	clone:Destroy()
end

Nothing is played now :thinking:

what if you just could make an new instance or an clone not with just id like this

local id = {1532584532,836718931}
local music = game.ReplicatedStorage.CurrentMusic:Clone()
while wait() do
	local main = music:Clone()
	local chosenid = id[math.random(1,#id)]
	main.SoundId = "rbxassetid://"..chosenid
	main.Parent = game.ReplicatedStorage
	main:Play()
	repeat wait() until main.IsPlaying == false
	main:Destroy()
end

i wish this will help you with you’r script pal, oops forgot to put real one

1 Like

can’t you just do this:

local songs = 
	{1532584532,
		836718931}

while true do

	local music = game.ReplicatedStorage.CurrentMusic

	local ID = songs[math.random(1,#songs)]
	music.SoundId = "rbxassetid://"..ID
	music.TimePosition = 0
	music:Play()
	music.Ended:Wait()

	music:Destroy()
end

if its not cloned or an instance it will play only one song because you just destroy it after it ends

yeah I know i just used OP’s original script and added one line of code.

TimePosition… but arent it like already starts from start? maybe if it like set to bigger but whatever

I want to create a script where music is played automatically and always starts at 0.
But how do you make it that the music always starts at TimePosition 0?

that is what OP said.

but it already starts from 0. in you’r script even without time position only if time position is not 0

he didn’t meant littery TimePosition he meant from the start

Well I am not sure, OP said he wanted the music to start from the beginning.