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

Automatically sets the Bool to false?

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)


2 answers

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.

5 comments

0

STOP STEALING STUFF I WANT TO ANSWER LUNATE >:O

0

You didn't answer it, and I was in Studio for most of the time. Be faster or provide better answers.

0

I have another script that works on TimeLength though..? and it works perfectly? @kool put in your answer too

0

When you find a better solution that answers your question, please do tell me.

0

I posted it down below.

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)


2 comments

0

I stand corrected. Does this mean that TimeLength is no longer broken?

0

I believe that in some forms that it can break like my first script, but it can work if you script it right.

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