Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

The text label's text isn't changing accordingly. Why and how can I fix it?

I'm trying to make a random music player script. I'm adding more songs but here is what I've got for now. What do I have to fix and or what did I do wrong?

title = game.StarterGui.He.Box.Song
function Playsong()
local number = math.random(1,2)
if number == 1 then
	script.Sound1:Play()
	title.Text = "Hate Me"
	wait(15)
	script.Sound1:Stop()
	title.Text = "No Song Playing"
	wait(3)
	title.Text = "Loading Song"
	wait(3)
	Playsong()
else if number == 2 then
	script.Sound2:Play()
	title.Text = "Stitches"
	wait(120)
	script.Sound2:Stop()
	title.Text = "No Song Playing"
	wait(1)
	title.Text = "Loading Song"
	wait(1)
	Playsong()
end
end
end


Playsong()

1 comment

1

elseif should not have a space in it

1 answer

✓ Accepted answer

Hello,

You've made mistakes on several lines so I will copy your Lua code and add corrections where you've gone wrong.

title = game.StarterGui.He.Box.Song -- Should be game.Players.LocalPlayer.PlayerGui.He.Box.Song
function Playsong()
local number = math.random(1,2)
if number == 1 then
    script.Sound1:Play()
    title.Text = "Hate Me"
    wait(15)
    script.Sound1:Stop()
    title.Text = "No Song Playing"
    wait(3)
    title.Text = "Loading Song"
    wait(3)
    Playsong()
else if number == 2 then -- 'Else if' doesn't exist. It's just 'elseif'
    script.Sound2:Play()
    title.Text = "Stitches"
    wait(120)
    script.Sound2:Stop()
    title.Text = "No Song Playing"
    wait(1)
    title.Text = "Loading Song"
    wait(1)
    Playsong()
end
end
end


Playsong()

If this answers your problem perfectly, then make sure to make this an accepted answer. If you have any questions also just comment them.

2 comments

0

The Random.new():NextInteger(1,2) does that go after Local Number =?

0

yep

This discussion is preserved as it was. New answers, comments, and votes are closed.