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

how do i make the text of a GUI>TextLable change?

when I get the value of Playing its true and why won't this work

if game.Workspace.MusicScript.S1.Playing == true then
script.Parent.Text = "Song: party"
end

2 comments

0

othere than the fact that you can use "workspace" instead of game.Workspace i see no errors in this code, so it may be somewhere else, show us more of it

0

Might be because you do the check if the sound is playing before it has started playing. You could make a while loop to wait for the sound to start playing.

4 answers

✓ Accepted answer

It's because it is only checking once. Do:

while true do
	if game.Workspace.MusicScript.S1.Playing == true then
		script.Parent.Text = "Song: party"
	end
	wait()
end

The reason it's not working is because it need to be constantly checking, a while true loop or while wait loop would work. Example:

while wait(0.1) do
if game.Workspace.MusicScript.S1.Playing == true then
script.Parent.Text = "Song: party"
end
end

That is probably the most simple but inefficient way of doing it. It SHOULD work though!

1 comment

0

nope

The most efficient way is runservice (stepped) i believe, give it a try as it rely's on a roblox service and not fully on the client (won't cause memory leaks)

game:GetService("RunService").Stepped:Connect(function()
           game:GetService("RunService").Stepped:Wait()
              if game.Workspace.MusicScript.S1.Playing == true then
                script.Parent.Text = "Song: party"
         end
end)
 
local sound = workspace:WaitForChild("MusicScript").S1
sound.Played:Connect(function() -- Connect a function once the sound starts to play
	script.Parent.Text = "Song: party"
end)

the reason for workspace:WaitForChild is that most of the times the player and its scripts loads faster than the game itself, so only necessary in studio.

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