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

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

Asked by 4 years ago

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

1if game.Workspace.MusicScript.S1.Playing == true then
2script.Parent.Text = "Song: party"
3end
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 Nogalo 148 — 4y
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. TheWaterFoox 255 — 4y

4 answers

Log in to vote
1
Answered by 4 years ago

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

1while true do
2    if game.Workspace.MusicScript.S1.Playing == true then
3        script.Parent.Text = "Song: party"
4    end
5    wait()
6end
Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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:

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

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

0
nope LTRNightmare 66 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)

1game:GetService("RunService").Stepped:Connect(function()
2           game:GetService("RunService").Stepped:Wait()
3              if game.Workspace.MusicScript.S1.Playing == true then
4                script.Parent.Text = "Song: party"
5         end
6end)
Log in to vote
0
Answered by 4 years ago
1local sound = workspace:WaitForChild("MusicScript").S1
2sound.Played:Connect(function() -- Connect a function once the sound starts to play
3    script.Parent.Text = "Song: party"
4end)

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.

Answer this question