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?

wait(0.5)
game.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

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

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

-- Server Script
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    wait(.5)
    Player.PlayerGui.ScreenGui.TextButton.Text = "io"
end)
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.

local TextButton = script.Parent.TextButton

wait(.5)
TextButton.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