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

How do I make a number have corresponding text?

Asked by 4 years ago
Edited 4 years ago

Hello. I am making a remake of Flood EScape 2 and I was wondering how tomake a number have a corresponding text. For example, one is easy. Here is my script so far:

1if Difficulty.Value = 1 then
2    TextName3.Text = Easy
3end

Here are the variables:

1local Difficulty = game.Workspace.Lost_Forest.Settings.Difficulty
2local TextName3 = game.StarterGui.ScreenGui.TextName3
0
Is game.Workspace.Lost_FOrest.Settings.Difficulty an IntValue? DemGame 271 — 4y
0
Forest* DemGame 271 — 4y
0
yes Borkingforlife 9 — 4y
0
Yes Borkingforlife 9 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

You can use a dictionary to define what each number means.

It would look like this:

1Local names = {
2["1"] = "Easy",
3["2"] = "Normal",
4["3"] = "Hard",
5}

You can easily get the value of your key like this:

1TextName3.Text = names[Difficulty.Value]

You can use an array/table too if you are only using numbers to call a value.

0
Sorry, but this answer doesn't work. The output is "Workspace.Lost_Forest.SettingsScript:21: invalid argument #3 (string expected, got nil)" Borkingforlife 9 — 4y
Ad
Log in to vote
0
Answered by
DemGame 271 Moderation Voter
4 years ago
Edited 4 years ago

The main problem with your script is on line 2, as "Easy" isn't a defined variable yet. You can also use an array to convert numbers into strings quickly without making 3 extra lines of code.

You can also use a function to actively change the gui's text.

Here's your edited code:

1local Difficulty = workspace["Lost_Forest"].Settings.Difficulty
2local TextName3 = game.StarterGui.ScreenGui.TextName3
3local DifficultiesArray = {"Easy", "Medium", "Hard", "Insane", "Crazy"}
4 
5--Heres a tip!: You can replace "game.Workspace" with just "workspace".
6 
7Difficulty.Changed:Connect(function()
8    TextName3.Text = DifficultiesArray[Difficulty.Value]
9end)
0
uhhm you speed replace wrong snowpototoy 37 — 4y
0
Thanks! I'll check this out. Borkingforlife 9 — 4y
0
can I replace the function with an onTouch function? Borkingforlife 9 — 4y
0
can I replace the function with an onTouch function? Borkingforlife 9 — 4y
View all comments (2 more)
0
sure DemGame 271 — 4y
0
ok Borkingforlife 9 — 4y

Answer this question