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

How to complete path when Square Brackets and Double Quotation marks are given?

Asked by 5 years ago


local sound1 = 532933680 local sound2 = 663850511 local sound3 = 1239252570 local sound4 = 447293921 local sound5 = 656434255 local sound6 = 316677879 local sound7 = 518562191 local sound8 = 233471598 local sound9 = 412765335 local music = script.Parent while true do wait() music.SoundId = "rbxassetid://"..sound1 music:Play() game.StarterGui.ScreenGui.Settings["Now Playing"].Song name.Text = 'Song name' music.Ended:Wait() music.SoundId = "rbxassetid://"..sound2 music:Play() music.Ended:Wait() music.SoundId = "rbxassetid://"..sound3 music:Play() music.Ended:Wait() music.SoundId = "rbxassetid://"..sound4 music:Play() music.Ended:Wait() music.SoundId = "rbxassetid://"..sound5 music:Play() music.Ended:Wait() music.SoundId = "rbxassetid://"..sound6 music:Play() music.Ended:Wait() music.SoundId = "rbxassetid://"..sound7 music:Play() music.Ended:Wait() music.SoundId = "rbxassetid://"..sound8 music:Play() music.Ended:Wait() music.SoundId = "rbxassetid://"..sound9 music:Play() music.Ended:Wait() end

So I want to change the text of a label in Starter Gui with a script in Workspace. The script is the child of a sound.

Code is on top

At line 16 the path has square brackets and double quotation marks. I tried using a '.' to complete the path but it didn't work.

Please help me!!

0
You would have to bind your song names to the Ids programmerHere 371 — 5y
0
How? nkminion 21 — 4y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Use square brackets again.

 game.StarterGui.ScreenGui.Settings["Now Playing"]["Song name"].Text = "Song name"

But to avoid this, since it can be messy, just remove the spaces and name it NowPlaying and SongName.

But this code is far from perfect. Why are you setting the music ID one-by-one when a loop can do this for you.

Have a table contain the IDs, then traverse the table and wait for it to play to go on to the next ID.

local client = game:GetService("Players").LocalPlayer
local song_ids = {
    532933680, 663850511, 1239252570,
    447293921, 656434255, 316677879,
    518562191, 233471598, 412765335
}

local music = script.Parent
local now_playing = client.PlayerGui.ScreenGui.Settings.NowPlaying
local song_name_label = now_playing.SongName -- if renamed to this it works

while true do -- You don't need that wait() call it does nothing useful
    for _, song_id in ipairs(song_ids) do
        music.SoundId = string.format("rbxassetid://%d", song_id)
        music:Play()
        song_name_label.Text = "Song name"
        music.Ended:Wait() -- Will wait for music to end to go onto next
    end
end

I'm not sure where this is parented at, I know it's in a Sound, but where is that sound.

You do not access the player's UI from StarterGui. You access it from their PlayerGui.

0
The sound is present in the workspace nkminion 21 — 5y
0
How do I change the song name at line 16 nkminion 21 — 5y
0
@programmerHere How do I change the song name every time a new song plays at line 16 nkminion 21 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Use square brackets again.

 game.StarterGui.ScreenGui.Settings["Now Playing"]["Song name"].Text = "Song name"

But to avoid this, since it can be messy, just remove the spaces and name it NowPlaying and SongName.

But this code is far from perfect. Why are you setting the music ID one-by-one when a loop can do this for you.

Have a table contain the IDs, then traverse the table and wait for it to play to go on to the next ID.

local client = game:GetService("Players").LocalPlayer
local song_ids = {
    532933680, 663850511, 1239252570,
    447293921, 656434255, 316677879,
    518562191, 233471598, 412765335
}

local music = script.Parent
local now_playing = client.PlayerGui.ScreenGui.Settings.NowPlaying
local song_name_label = now_playing.SongName -- if renamed to this it works

while true do -- You don't need that wait() call it does nothing useful
    for _, song_id in ipairs(songs) do
        music.SoundId = string.format("rbxassetid://%d", song_id)
        music:Play()
        song_name_label.Text = "Song name"
        music.Ended:Wait() -- Will wait for music to end to go onto next
    end
end

I'm not sure where this is parented at, I know it's in a Sound, but where is that sound.

You do not access the player's UI from StarterGui. You access it from their PlayerGui.

Answer this question