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 3 years ago
Edited 3 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:

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

Here are the variables:

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

2 answers

Log in to vote
0
Answered by 3 years ago

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

It would look like this:

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

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


TextName3.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 — 3y
Ad
Log in to vote
0
Answered by
DemGame 271 Moderation Voter
3 years ago
Edited 3 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:

local Difficulty = workspace["Lost_Forest"].Settings.Difficulty
local TextName3 = game.StarterGui.ScreenGui.TextName3
local DifficultiesArray = {"Easy", "Medium", "Hard", "Insane", "Crazy"}

--Heres a tip!: You can replace "game.Workspace" with just "workspace".

Difficulty.Changed:Connect(function()
    TextName3.Text = DifficultiesArray[Difficulty.Value]
end)
0
uhhm you speed replace wrong snowpototoy 37 — 3y
0
Thanks! I'll check this out. Borkingforlife 9 — 3y
0
can I replace the function with an onTouch function? Borkingforlife 9 — 3y
0
can I replace the function with an onTouch function? Borkingforlife 9 — 3y
View all comments (2 more)
0
sure DemGame 271 — 3y
0
ok Borkingforlife 9 — 3y

Answer this question