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

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

Asked by 4 years ago
Edited 4 years ago

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!

0
Is label the name of the textlabel? SilentsReplacement 468 — 4y
0
yes reboticguy1000 0 — 4y
0
it's a variable reboticguy1000 0 — 4y

1 answer

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

Explanation

This is a really easy and simple question. Make sure that the script is a local script else this script won't work and can possibly bring errors..

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)

I also recommend you adding variables..

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..

0
Thank you so much reboticguy1000 0 — 4y
0
Please select this as your answer and upvote! SilentsReplacement 468 — 4y
Ad

Answer this question