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

attempt to call field 'Text' (a string value) error?

So, I am trying to make a textbox if where you put 0.9, it will put the car's height like a lowrider. But it is not changing and gives me this error: 18:05:06.931 - Players.squidiskool.PlayerGui.ScreenGui.TextBox.Script:1: attempt to call field 'Text' (a string value)

Here is the code if you want to look further:

if script.Parent.Text ("0.9") then 
	game.Workspace.body.Position ("5.167")
end

I am a beginner in coding, so I am not perfect.

4 answers

✓ Accepted answer

Hey, so this should work.

local Box = script.Parent
Box.FocusLost:Connect(function(enterPressed)
if enterPressed then
	print("Input recieved")
end
local Number = ("0.9")
if Box.Text == (Number) then
print("Input is equal to number")
--Add your stuff here
end
end)

Make a local script with these lines & put it inside a textbox. It will compare the input to the number you specify and perform an action if correct.

6 comments

0

It just prints out something and nothing happens.

0

Mhm, you add what you want to happen in the '--Add your stuff here' line.

0

Yep, I did that.

0

You can simply add the line that @repgainer3 posted. I've tested this in studio and it works.

0

Oops, forgot to add something and now it works!

0

Haha, happens to everyone. Goodluck with your project!

I did change the code a bit, but it still outputs the error.

if script.Parent.Text ("0.9") then 
	game.Workspace.body.Position ("-5.408, 4.167, 21.135")
end

First, use == for comparing two values if they equal.

Second, .Positions arent just one value. Imagine it's a value containing 3 other values.

This value for .Position is Vector3. Vector3 contains X, Y, and Z. To set the .Position, feed it a Vector3 value.

workspace.body.Position = Vector3.new(X, Y, Z)

X would be numbers of X coordinate, Y would be numbers of Y coordinate, and Z would be numbers of Z coordinate.

3 comments

0

I didn't quite catch what first meant, but I changed it to the Vector3.new thing and it still is not working

0

You don't do things like: if text "hi" then. You use the == to compare if two values are the same, so it would become if text == "hi" then.

0

I did that, but it still doesn't change the position and there is no error outputting.

Hi, I'm not sure where you learned how to compare values like that, but here is your code but functional.

if script.Parent.Text == "0.9" then 
    workspace.body.Position = Vector3.new(-5.408, 4.167, 21.135)
end

3 comments

0

I learned that from just my knowledge.

0

Also, if there is no error, that means that script.Parent.Text doesn't equal "0.9", and you should check what the value actually is using a print(script.Parent.Text) statement.

0

Using the statement does not do anything.

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