Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I can't make a script that would restart a song after a random time?

I am new to scripting so I failed.

4 comments

0

learn the basics of lua first before coming here, at least knowing the basics of lua is a must when coming here for help

0

Give us some Code because thats not a Script Requesting Site!

0

This is not a request site

0

Whelp, I made a mistake. sorry for that

1 answer

✓ Accepted answer

I'm not entirely sure if this is what you are asking for since the question itself is some-what bland. But feel free to let me know if you meant something else.

Assuming you want everyone to hear the song, it'd have to be a **Server ** script, and it should be placed in ServerScriptService.

Then from here, first you'd have to set up your variables before coding the function to make it a lot easier to read and understand if you were to make edits.

local SongID = 0 -- Change this to the song ID of your choosing.

local waitLength = math.random(60,300) -- This will wait between 60 and 300 seconds before playing your song, feel free to edit this. The first number being the minimum, and last number being maximum wait times.

function playSong() -- This is your function
	
	wait(waitLength)
	
	local Sound = Instance.new('Sound', workspace) -- Creates sound instance and parents it.
	Sound.Name = 'Song' -- Name it whatever is easier for you.
	Sound.Volume = .5 -- .5 is default, but you can change the volume to whatever you wish.
	Sound.SoundId = 'rbxassetid://'..SongID -- Puts your song ID

	repeat wait() until Sound.IsLoaded == true -- Waits until the song loads up.

	Sound:Play() -- Will play your audio.

	Sound.Ended:Connect(function() -- Will wait until the song has finished playing.
		if Sound then Sound:Destroy() end -- Removes current sound, if available.
		playSong() -- Will repeat the code as before, allowing it to play again.
	end)
end


playSong() -- First time setup of the function.

And there you have it, a few lines of code for a random song play. Feel free to edit whatever any of the variables to your liking. If you have any questions don't be afraid to ask.

1 comment

0

Yeah my bolding text didn't go as planned, but you get the point.

This discussion is preserved as it was. New answers, comments, and votes are closed.