Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How to change text in gui using a script?

Asked by 7 days ago

Hi! So I have a music playlist, in Workspace, and a GUI with a TextLabel in StarterGUI. In the music playlist script, I added some code attempting to make the TextLabel state what song was playing when it started to play. It worked for the first song, but not any song after. I also noticed that only when using the admin command ;refresh in HDAdmin, did the TextLabel state what song was playing correctly. I don't understand why this is happening, as there is no output error, and the script looks correct. Any help would be greatly appreciated!!!!

song1 = "http://www.roblox.com/asset/?id=4872114478" 
song2 = "http://www.roblox.com/asset/?id=423031173"
song3 = "http://www.roblox.com/asset/?id=4700827910"

local music = Instance.new("Sound") 
music.Archivable = true 
local SONGPLAYING = game.StarterGui.SongGUI.Frame.TextLabel

music.Parent = script.Parent 
music.Pitch = 1 
music.Volume = 1 
music.Looped = false
music.Name = "Player"


while (true) do
    --1--
wait(5)
print 'Playing Sound 1'
    music.SoundId = song1 
    SONGPLAYING.Text = "Playing: Goodnight n Say So - Mashup "
    music:play()
        wait(130) 
    --2--
print 'Playing Sound 2'
    music.SoundId = song2
    SONGPLAYING.Text = "Playing: Doja Cat - Trauma"
    music:play()    
        wait(130)
    --3--
print 'Playing Sound 3'
    music.SoundId = song3
    SONGPLAYING.Text = "Playing: Doja cat - Cyber"
    music:play()
        wait(130)   
end
0
Is it printing Playing Sound 1 2 or 3 ? Tizzel40 225 — 7d
0
Please be more exact 7zjh 74 — 6d
0
I was asking if Lines 19 , 25 , or 31 had printed "Playing Sound 1,2 or 3" , but I already have an answer posted for you buddy ! Tizzel40 225 — 6d
0
I don't know the globals your trying to go to 7zjh 74 — 6d
0
I don't know the globals your trying to go to 7zjh 74 — 6d

1 answer

Log in to vote
1
Answered by
Tizzel40 225 Moderation Voter
6 days ago

On line 7 , you had put game.StarterGui . This wont work becuase it is not getting the player's Gui to do anything , its getting the Starter Gui , to do an action , and the starter Gui is there ui that is given to the player when they boot up the game

on line 7 you should The PlayerGui rather than the StarterGui

You can do this by getting the player like this :

local player = game.Players.LocalPlayer

local playergui = player:WaitForChild("PlayerGui")---Located inside the player. I placed a Wait For Child because It may not always Load as Fast !


then on line 7 it should be

    playergui.SongGUI.Frame.TextLabel

Not...

game.StarterGui.SongGUI.Frame.TextLabel

This Should work as its getting the UI From the Players UI :) !

Good day to you LiLFriks

--T40

0
hello! i got the error, (Workspace.playlist:31: attempt to index nil with 'WaitForChild'). I think it might be because my music playlist script is a normal script inside workspace. Please lmk if you know how to fix this, because when I make the playlist a server script and put it in somewhere other than workspace, it doesn't work :( LiLFriks 35 — 6d
0
nevermind! it works thx! LiLFriks 35 — 6d
0
Sorry I didnt reply to your first comment , I was busy with other people's questions! But it is nice to know it works ! Also Thank you for the acceptance ! :) ! Tizzel40 225 — 6d
Ad

Answer this question