Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

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. DeceptiveCaster 3761 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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.

Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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


0
This wouldn't work because of indirect assignment, please see my other comment DeceptiveCaster 3761 — 4y

Answer this question