Text Label text don't change

Hi,
I’m creating tycoon and when i try to change text label in billboard gui it works first 2 times but after it don’t works.
Here’s script: 99% people will leave after seeing it

local button = script.Parent.ClickDetector

button.MouseClick:Connect(function(p)
	if p.Team == game:GetService("Teams").WaterOrb and p.leaderstats["O-Bux"].Value >= 20 then
		p.leaderstats["O-Bux"].Value -= 20
		local wall = workspace.WOWall1:GetChildren()
		for _, v in pairs(wall) do
			v.CanCollide = true
			v.Transparency = 0
		end
		script.Parent.BillboardGui.TextLabel.Text = "Wall 2"
		script.Parent.BillboardGui1.TextLabel.Text = "60 O-Bux"
		button.MouseClick:Connect(function()
			if p.Team == game:GetService("Teams").WaterOrb and p.leaderstats["O-Bux"].Value >= 60 then
				p.leaderstats["O-Bux"].Value -= 60
				local wall = workspace.WOWall2:GetChildren()
				for _, v in pairs(wall) do
					v.CanCollide = true
					v.Transparency = 0
				end
				script.Parent.BillboardGui.TextLabel.Text = "Wall 3"
				script.Parent.BillboardGui1.TextLabel.Text = "120 O-Bux"
				button.MouseClick:Connect(function()
					if p.Team == game:GetService("Teams").WaterOrb and p.leaderstats["O-Bux"].Value >= 120 then
						p.leaderstats["O-Bux"].Value -= 120
						local wall = workspace.WOWall3:GetChildren()
						for _, v in pairs(wall) do
							v.CanCollide = true
							v.Transparency = 0
						end
						script.Parent.BillboardGui.TextLabel.Text = "Wall 4"
						script.Parent.BillboardGui1.TextLabel.Text = "340 O-Bux"
						button.MouseClick:Connect(function()
							if p.Team == game:GetService("Teams").WaterOrb and p.leaderstats["O-Bux"].Value >= 340 then
								p.leaderstats["O-Bux"].Value -= 340
								local wall = workspace.WOWall4:GetChildren()
								for _, v in pairs(wall) do
									v.CanCollide = true
									v.Transparency = 0
								end
								script.Parent.BillboardGui.TextLabel.Text = "Wall 5"
								script.Parent.BillboardGui1.TextLabel.Text = "700 O-Bux"
								button.MouseClick:Connect(function()
									if p.Team == game:GetService("Teams").WaterOrb and p.leaderstats["O-Bux"].Value >= 700 then
										p.leaderstats["O-Bux"].Value -= 700
										local wall = workspace.WOWall5:GetChildren()
										for _, v in pairs(wall) do
											v.CanCollide = true
											v.Transparency = 0
										end
										script.Parent.BillboardGui.TextLabel.Text = "Roof 1"
										script.Parent.BillboardGui1.TextLabel.Text = "2000 O-Bux"
										button.MouseClick:Connect(function()
											if p.Team == game:GetService("Teams").WaterOrb and p.leaderstats["O-Bux"].Value >= 2000 then
												p.leaderstats["O-Bux"].Value -= 2000
												local wall = workspace.WORoof1:GetChildren()
												for _, v in pairs(wall) do
													v.CanCollide = true
													v.Transparency = 0
												end
												script.Parent.Transparency = 1
												script.Parent.BillboardGui.Enabled = false
												script.Parent.BillboardGui1.Enabled = false
												button:Destroy()
											end
										end)
									end
								end)
							end
						end)
					end
				end)
			end
		end)
	end
end)

where in the script is it not working

When I change the BillboardGui.TextLabel.Text value but it works 2 first times

ok ima check the code out then

could you test with prints and see how far the code gets?

everything works without these text labels

oh ok so the code runs at all the parts of the code, and you get no errors?

yes no errors (need 3 0 l e t t e r s)

I feel like if it isn’t working then you have your if statements saying that its statement is false

whenever it’s happening to me I do:

local text = script.Parent.BillboardGui.TextLabel
text.Text = -- text

instead of:

script.Parent.BillboardGui.TextLabel.Text = -- text

and it’s working but idk how

1 Like

odd I never get this problem when coding
I wonder why it does this

I said everything other works!!!

just making sure cuz I’m out of ideas, sorry :joy:

Oh dear that’s a lot of unnecessary code

It would just be a whole lot more simpler to reference more local variables instead of using nested loops

local Button = script.Parent.ClickDetector
local CurrentLevel = 1
local CurrentCost = 20

Button.MouseClick:Connect(function(p)
    local Bux = p:WaitForChild("leaderstats"):WaitForChild("O-Bux")
    if p.Team == game:GetService("Teams").WaterOrb and Bux.Value >= CurrentCost then
        Bux.Value -= CurrentCost

        if CurrentLevel == 1 then
            CurrentCost = 60

	        local wall = workspace.WOWall1:GetChildren()
		    for _, v in pairs(wall) do
			    v.CanCollide = true
			    v.Transparency = 0
		    end
		    script.Parent.BillboardGui.TextLabel.Text = "Wall 2"
		    script.Parent.BillboardGui1.TextLabel.Text = "60 O-Bux"

        elseif CurrentLevel == 2 then
            CurrentCost = 120

	        local wall = workspace.WOWall2:GetChildren()
		    for _, v in pairs(wall) do
			    v.CanCollide = true
			    v.Transparency = 0
		    end
		    script.Parent.BillboardGui.TextLabel.Text = "Wall 3"
		    script.Parent.BillboardGui1.TextLabel.Text = "120 O-Bux"
        elseif CurrentLevel == 3 then
            CurrentCost = 340

	        local wall = workspace.WOWall3:GetChildren()
		    for _, v in pairs(wall) do
			    v.CanCollide = true
			    v.Transparency = 0
		    end
		    script.Parent.BillboardGui.TextLabel.Text = "Wall 4"
		    script.Parent.BillboardGui1.TextLabel.Text = "340 O-Bux"

        elseif CurrentLevel == 4 then
            CurrentCost = 700

	        local wall = workspace.WOWall4:GetChildren()
		    for _, v in pairs(wall) do
			    v.CanCollide = true
			    v.Transparency = 0
		    end
		    script.Parent.BillboardGui.TextLabel.Text = "Wall 5"
		    script.Parent.BillboardGui1.TextLabel.Text = "700 O-Bux"

        elseif CurrentLevel == 5 then
            CurrentCost = 2000

	        local wall = workspace.WOWall5:GetChildren()
		    for _, v in pairs(wall) do
			    v.CanCollide = true
			    v.Transparency = 0
		    end
		    script.Parent.BillboardGui.TextLabel.Text = "Roof 1"
		    script.Parent.BillboardGui1.TextLabel.Text = "2000 O-Bux"

        elseif CurrentLevel == 6 then
            CurrentCost = math.huge

	        local wall = workspace.WORoof1:GetChildren()
		    for _, v in pairs(wall) do
			    v.CanCollide = true
			    v.Transparency = 0
		    end
			script.Parent.Transparency = 1
			script.Parent.BillboardGui.Enabled = false
			script.Parent.BillboardGui1.Enabled = false
			button:Destroy()
        end
        CurrentLevel += 1
    end
end)

Please try this :slightly_smiling_face: If nothing works, do add print() statements for debugging

1 Like

thanks this is much easier on the eyes

2 Likes

Thanks, everything works (this code have more lines but it’s better)

now that I think about it after looking at the new code I forgot that your problem most likely had to do with you adding multiple MouseClick functions inside each other

Yeaaaah

For sanity purposes @SuchTheLegendary, please don’t take events to a point to do this:

image

You should keep it simple & organized with 1 event maintaining all of your conditional checks

2 Likes

this monstrosity…

gotta respect the ends tho, pretty nice