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

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
the parent is a button right? If so, look at my answer. hihowareya115 53 — 4y
0
yes, the parent is the button reboticguy1000 0 — 4y
0
did my answer work? hihowareya115 53 — 4y
0
No, the button didn't do anything reboticguy1000 0 — 4y
View all comments (2 more)
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? hihowareya115 53 — 4y
0
I accidentally posted two. This is my first time on the website reboticguy1000 0 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago
script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Text = "Example Text"
end)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Answer this question