Attempt to index string with 'Text'

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make that when a player presses a button it generates a random text.
  2. What is the issue? Include screenshots / videos if possible!
    I keep getting this error “attempt to index string with ‘Text’”.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I look for solutions on the dev hub.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local WordNeededStr = ""
local GeneratedWordStr = ""
local PossibleWords = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "}
print(#PossibleWords)
local LoadingScreen = script.Parent.LoadingScreen
local LoadingPlayButton = LoadingScreen.Play
local LoadingLoadInfo = LoadingScreen.LoadInfo

local MainScreen = script.Parent.Main
local CTBL = MainScreen.ChanceToBeatLevel
local GeneratedWord = MainScreen.GeneratedWord
local NeededWord = MainScreen.NeededWord
local Plr = game.Players.LocalPlayer
local PlrLevel = Plr:WaitForChild("leaderstats").Level
local GenerateText = MainScreen.GenerateText

local ChanceToBeatLevelStr = "1/"..tostring(#PossibleWords * PlrLevel.Value)
local ChanceToBeatLevelNum = 1/(#PossibleWords * PlrLevel.Value)
print(ChanceToBeatLevelStr)
print(ChanceToBeatLevelNum)


if WordNeededStr == "" or WordNeededStr == nil then
	NeededWord.Text = "There is no needed word, Press the \"change required word\" button at the bottom left"
end

if GeneratedWordStr == "" or GeneratedWordStr == nil then
	GeneratedWord.Text = "There is no generated word, Press the \"Generate Word\" button at the bottom left"
end

local function PlayButtonActivated()
	LoadingPlayButton:Destroy()
	wait()
	LoadingLoadInfo.Text = "Loading Player (0%)"
	wait(0.1)
	LoadingLoadInfo.Text = "Loading Player (40%)"
	wait(0.3)
	LoadingLoadInfo.Text = "Loading Player (90%)"
	wait(0.05)
	LoadingLoadInfo.Text = "Loading Player (100%)"
	wait(0)
	LoadingLoadInfo.Text = "Loading Player Data (0%)"
	wait(0.6)
	LoadingLoadInfo.Text = "Loading Player Data (15%)"
	wait(0.5)
	LoadingLoadInfo.Text = "Loading Player Data (75%)"
	wait(0.7)
	LoadingLoadInfo.Text = "Loading Player Data (100%)"
	wait(0)
	LoadingLoadInfo.Text = "Loading AntiCheat (0%)"
	wait(1)
	LoadingLoadInfo.Text = "Loading AntiCheat (90%)"
	wait(0.3)
	LoadingLoadInfo.Text = "Loading AntiCheat (100%)"
	wait(0.1)
	LoadingLoadInfo.Text = "Loading Systen (0%)"
	wait(0.3)
	LoadingLoadInfo.Text = "Loading System (10%)"
	wait(0.3)
	LoadingLoadInfo.Text = "Loading System (40%)"
	wait(0.3)
	LoadingLoadInfo.Text = "Loading System (80%)"
	wait(0.3)
	LoadingLoadInfo.Text = "Loading System (100%)"
	wait(1)
	LoadingLoadInfo.Text = "Game Loaded"
	wait(2)
	LoadingScreen:TweenPosition(UDim2.new(0,0,-1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.5, false)
	wait(0.5)
	LoadingScreen:Destroy()
end

local function SetWord(Text: string, plrlevel: number)
	if not Text then return end
	
	if not plrlevel then return end
	
	WordNeededStr = Text
	NeededWord.Text = "The Word needed is: ".. WordNeededStr
end

local function GenerateRandomWord()
	print(GeneratedWordStr.."1")
	if WordNeededStr == "" or WordNeededStr == nil then return end
	print(GeneratedWordStr.."2")
	for i = 1,PlrLevel.Value do
		local GetNumber = math.random(1,#PossibleWords)
		local RandomLetter = PossibleWords[GetNumber]
		GeneratedWordStr.Text = GeneratedWordStr..RandomLetter
	end
	print(GeneratedWordStr.."3")
end

SetWord("hhhahsahgh", PlrLevel.Value)

LoadingPlayButton.MouseButton1Click:Connect(PlayButtonActivated)
GenerateText.MouseButton1Click:Connect(GenerateRandomWord)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

the error is at this line, at the end of the script:
GeneratedWordStr.Text = GeneratedWordStr..RandomLetter

1 Like

oh wait, i noticed the problem.

I’m trying to set a text of a string which doesn’t make sense.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.