When the music plays it should set the bool to true, then wait(song.TimeLength) to change back to false, but it doesn't?
When the song is played the bool just stays false..?
--[[SONG SCRIPT]]-- local song = script.Parent.Parent.Parent.Song local value = script.Parent.Parent.Parent.CurrentlyPlaying local value2 = script.Parent.Parent.Playing local id = script.Parent.ID.Value local timev = script.Parent.Parent.Parent.BAR.Time function clicked(player, name) if value.Value == false then value.Value = true value2.Value = script.Parent.Text song.SoundId = "rbxassetid://"..(id) song:Play() wait(song.TimeLength) song:Stop() value.Value = false end end script.Parent.MouseButton1Down:connect(clicked)
TimeLength
doesn't work on the server
Consider moving to a LocalScript, or using the Ended event instead.
Why? The server doesn't actually load the sound, and doesn't even play it. It simply tells the clients to play it, and they load the sound themselves. In fact, the server doesn't even know that the clients are all playing the same sound. As a result, it simply has no way of determining how long the sound is.
I figured it out, this works perfectly.
local SoundInstance = game.Workspace.VritixConsole.MainWall.SurfaceGui.Song local id = script.Parent.ID.Value local value = script.Parent.Parent.Parent.CurrentlyPlaying x =1 function run() SoundInstance.SoundId="rbxassetid://"..id wait(1) song=SoundInstance song:Play() for i=1,10 do song.Volume = song.Volume + 0.1 wait(0.1) end wait(song.TimeLength) for i=1,10 do song.Volume = song.Volume - 0.1 wait(0.1) end song:Stop() value.Value = false wait(1) end function click() if value.Value == false then value.Value = true run() else if value.Value == true then print "Another song is already playing!" end end end script.Parent.MouseButton1Down:connect(click)