Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a number have corresponding text?

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

4 comments

0

Is game.Workspace.Lost_FOrest.Settings.Difficulty an IntValue?

0

Forest*

0

yes

0

Yes

2 answers

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.

1 comment

0

Sorry, but this answer doesn't work. The output is "Workspace.Lost_Forest.SettingsScript:21: invalid argument #3 (string expected, got nil)"

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)

6 comments

0

uhhm you speed replace wrong

0

Thanks! I'll check this out.

0

can I replace the function with an onTouch function?

0

can I replace the function with an onTouch function?

0

sure

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.