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

Everything Runs, Text Won't Change!?

Asked by
thesit123 509 Moderation Voter
7 years ago

Background - I have a 2 scripts, local, that shows the number of games that are current being held and the numbers of available games (Which is, when no games are being held, 25).

PROBLEM - So everything runs fine, I added print() to show that it's working. Yeah all and that, but when changing the text, it won't change.

FAILED SOLUTIONS - 1: I tried adding tostring and tonumber, but it doesn't work, or I just did it wrong. But why would the scripts print the numbers correctly, like there's no problem at all?

2: I've tried directly changing the text instead of changing values and then set the text.

| SCRIPT 1: CHANGING VALUES |

while wait(0.1) do
    script.Parent.GamesCurrentV.Value = game.Workspace.Games.GamesNow.Value
    script.Parent.AvaGamesV.Value = 25 -script.Parent.GamesCurrentV.Value
end

| SCRIPT 2: CHANGING TEXT |

while wait(0.01) do
    local ag = script.Parent.AvaGames.Text
    local agv = script.Parent.AvaGamesV.Value

    local gc = script.Parent.GameCurrent.Text
    local gcv = script.Parent.GamesCurrentV.Value

    ag = agv
    gc = gcv
end

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago

I appreciate that you actually tried to solve it yourself, kudos for that.

local ag = script.Parent.AvaGames.Text

The problem here is that you made the variable equal to an object's property (Text). When you do that, the variable will become equal to the property's value, but it doesn't actually keep a reference to the original object. So if the text is "Hello world" then ag will only equal the string "Hello world."

So what that means is that when you edit ag, the variable ag will change, but the actual object won't.

Just make you variables equal to the object, then edit their properties from there.

local ag = script.Parent.AvaGames

ag.Text = "whatever text you want"
0
Thank You! I learn something new everyday! thesit123 509 — 7y
Ad

Answer this question