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

How do I change the text of a label using a button?

Hi, I have a problem changing my textlabel's text. This is my current script

local Button = script.Parent local Label = game.StarterGui.ScoreboardGui.Scoreboard.Main.Home.Main.TeamName Button.MouseButton1Click:Connect(function() Label.Text = "hi" end)

Hope there is a way you can help me, thanks!

6 comments

0

the parent is a button right? If so, look at my answer.

0

yes, the parent is the button

0

did my answer work?

0

No, the button didn't do anything

0

let me rephrase my question if it helps. Is the parent of script a TextButton? And is it a local script or a script?

0

I accidentally posted two. This is my first time on the website

2 answers

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Text = "Example Text"
end)

This is a really easy and simple question. I can't see any mistakes on your script since you haven't posted it in proper code format. Make sure that the script is alocal script..

Solution

local Button = script.Parent  -- Define the Textbutton
local Label = game.StarterGui.ScoreboardGui.Scoreboard.Main.Home.Main.TeamName 

Button.MouseButton1Click:Connect(function()
	label.Text = "Hi" -- Change Hello to what you want the text to be..
end)

Example 2

local Button = script.Parent -- Define the Textbutton
local Label = game.StarterGui.ScoreboardGui.Scoreboard.Main.Home.Main.TeamName  

Button.MouseButton1Click:Connect(function()
	label.Text = "This is a local script"    -- -- Change **This is a local script** to what you want the text to be..
        wait(2) 
       label.Text = "Hello"  -- Change **Hello** to your own text if you would like to..
end)

Example 3

local Button = script.Parent -- Define the Textbutton
local label = game.StarterGui.ScoreboardGui.Scoreboard.Main.Home.Main.TeamName 

Button.MouseButton1Click:Connect(function()
	label.Text = "Hello"
       label.TextColor3 = Color3.new(255,0,0) -- 255,0,0 is a red color..
end)

I hope this helps you and please up vote and select this as your answer if it did so..

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