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

My Script should change the text in my TextButton, but it isn't, Can I have help?

Asked by 5 years ago

I don't know what I am doing wrong...

I'm trying to change the text in my TextButton but it wont change with this script, can I have some help?

1wait(0.5)
2game.StarterGui.ScreenGui.TextButton.Text = ("io")

2 answers

Log in to vote
0
Answered by 5 years ago

Once the game starts, anything in StarterGui that gets modified will not change for players already in the game. To do this you either have to make a LocalScript inside of the object you want to change the text of and do a script as is

1-- Local Script
2wait(.5)
3script.Parent.Text = "io"

Another way to do this for when a player joins would be like this

1-- Server Script
2local Players = game:GetService("Players")
3 
4Players.PlayerAdded:Connect(function(Player)
5    wait(.5)
6    Player.PlayerGui.ScreenGui.TextButton.Text = "io"
7end)
Ad
Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
5 years ago

The reason why is that StarterGuis is basically a service that clones children within it to the PlayerGui of the player.

1local TextButton = script.Parent.TextButton
2 
3wait(.5)
4TextButton.Text = "io"

The code above is a local script that is inside of a ScreenGui. We get the textbutton and wait 0.5 seconds and then change the text to "io"

Answer this question