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:
1 | if Difficulty.Value = 1 then |
2 | TextName 3. Text = Easy |
3 | end |
Here are the variables:
1 | local Difficulty = game.Workspace.Lost_Forest.Settings.Difficulty |
2 | local TextName 3 = game.StarterGui.ScreenGui.TextName 3 |
You can use a dictionary to define what each number means.
It would look like this:
1 | Local names = { |
2 | [ "1" ] = "Easy" , |
3 | [ "2" ] = "Normal" , |
4 | [ "3" ] = "Hard" , |
5 | } |
You can easily get the value of your key like this:
1 | TextName 3. Text = names [ Difficulty.Value ] |
You can use an array/table too if you are only using numbers to call a value.
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:
1 | local Difficulty = workspace [ "Lost_Forest" ] .Settings.Difficulty |
2 | local TextName 3 = game.StarterGui.ScreenGui.TextName 3 |
3 | local DifficultiesArray = { "Easy" , "Medium" , "Hard" , "Insane" , "Crazy" } |
4 |
5 | --Heres a tip!: You can replace "game.Workspace" with just "workspace". |
6 |
7 | Difficulty.Changed:Connect( function () |
8 | TextName 3. Text = DifficultiesArray [ Difficulty.Value ] |
9 | end ) |