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

if game.Workspace.MusicScript.S1.Playing == true then
script.Parent.Text = "Song: party"
end
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:

while true do
    if game.Workspace.MusicScript.S1.Playing == true then
        script.Parent.Text = "Song: party"
    end
    wait()
end
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:

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!

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)

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)

Log in to vote
0
Answered by 4 years ago
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.

Answer this question