when I get the value of Playing its true and why won't this work
1 | if game.Workspace.MusicScript.S 1. Playing = = true then |
2 | script.Parent.Text = "Song: party" |
3 | end |
It's because it is only checking once. Do:
1 | while true do |
2 | if game.Workspace.MusicScript.S 1. Playing = = true then |
3 | script.Parent.Text = "Song: party" |
4 | end |
5 | wait() |
6 | 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:
1 | while wait( 0.1 ) do |
2 | if game.Workspace.MusicScript.S 1. Playing = = true then |
3 | script.Parent.Text = "Song: party" |
4 | end |
5 | end |
That is probably the most simple but inefficient way of doing it. It SHOULD work though!
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)
1 | game:GetService( "RunService" ).Stepped:Connect( function () |
2 | game:GetService( "RunService" ).Stepped:Wait() |
3 | if game.Workspace.MusicScript.S 1. Playing = = true then |
4 | script.Parent.Text = "Song: party" |
5 | end |
6 | end ) |
1 | local sound = workspace:WaitForChild( "MusicScript" ).S 1 |
2 | sound.Played:Connect( function () -- Connect a function once the sound starts to play |
3 | script.Parent.Text = "Song: party" |
4 | 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.