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

attempt to index local 'text' (a string value)?

This script should automatically and infinitely check an int value's value and insert it into my text in my textbutton.

local button = script.Parent.TextButton
local text = button.Text

while wait() do
	local num = game.Workspace:WaitForChild("NumParts").Value
	text.Value = ("Click to Place Parts! "..num.."/3 Parts.")
end

I keep on getting the error attempt to index local 'text' (a string value) and I don't know what to do about it.

EDIT: This is in a normal script

1 comment

0

A. The variable "text" is assigned to a string, not a value instance. B. The text will never change because of indirect assignment; the value of the variable changes but the text in the TextButton(?) does not.

2 answers

✓ Accepted answer

The Text property doesn't have a child named Value. The text is the actual string, meaning you can get rid of that .Value at the end there and it should fix it.

In the second line, you have already said .Text which is already a string value. I would also recommend using GetPropertyChangedSignal. loops can cause lag to your game.

local Button = script.Parent.TextButton
local Text = Button.Text -- As you see right here, you have already said .Text which is the string value.

while wait() do
	local num = game.Workspace:WaitForChild("NumParts").Value
	Text = ("Click to Place Parts! "..num.."/3 Parts.") -- We got rid of the .Value here since we already defined it on the Text variable.
end


1 comment

0

This wouldn't work because of indirect assignment, please see my other comment

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