Ad
Log in to vote
0

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

Asked by 1 year ago

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

Log in to vote
0
Answered by 1 year ago

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.

0
It just prints out something and nothing happens. squidiskool 200 — 1y
0
Mhm, you add what you want to happen in the '--Add your stuff here' line. jensar141215 157 — 1y
0
Yep, I did that. squidiskool 200 — 1y
0
You can simply add the line that @repgainer3 posted. I've tested this in studio and it works. jensar141215 157 — 1y
View all comments (2 more)
0
Oops, forgot to add something and now it works! squidiskool 200 — 1y
0
Haha, happens to everyone. Goodluck with your project! jensar141215 157 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

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
Log in to vote
0
Answered by
cegberry 412 Moderation Voter
1 year ago

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.

0
I didn't quite catch what first meant, but I changed it to the Vector3.new thing and it still is not working squidiskool 200 — 1y
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. cegberry 412 — 1y
0
I did that, but it still doesn't change the position and there is no error outputting. squidiskool 200 — 1y
Log in to vote
0
Answered by 1 year ago

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
0
I learned that from just my knowledge. squidiskool 200 — 1y
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. repgainer3 35 — 1y
0
Using the statement does not do anything. squidiskool 200 — 1y

Answer this question