Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

I am new to scripting so I failed.

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 LoganboyInCO 150 — 4y
0
Give us some Code because thats not a Script Requesting Site! RedstonecraftHD 25 — 4y
0
This is not a request site U_srname 152 — 4y
0
Whelp, I made a mistake. sorry for that ASTRa_NICs 9 — 4y

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
4 years ago

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.

0
Yeah my bolding text didn't go as planned, but you get the point. pwx 1581 — 4y
Ad

Answer this question