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

bad argument #3 to 'Text' (string expected, got nil)?

Asked by 5 years ago
Edited 5 years ago

I had this error and don't know how to fix it Here's the script:

function bhask(a, b, c)
    local delta = b^2 - 4 * a * c
    local x1 = (-b - math.sqrt(delta)) / (2 * a)
    local x2 = (-b + math.sqrt(delta)) / (2 * a)

    return x1, x2

end

a = script.Parent.Parent.A.Text
b = script.Parent.Parent.B.Text
c = script.Parent.Parent.C.Text

x1, x2 = bhask(a, b, c)
res = print(x1, x2)

script.Parent.Parent.Result.Text = res

1 answer

Log in to vote
0
Answered by 5 years ago

print has no return value.

Since it lacks a return value, res is assigned to nil.

If you want, you can concatenate the results into a single string, and display the text that way, or maybe format it kinda like this.

```lua local function bhask(a, b, c) local delta = b^2 - 4ac; local x1 = (-b - math.sqrt(delta))/(2a); local x2 = (-b + math.sqrt(delta))/(2a); return x1, x2; end

local frame = script.Parent.Parent; --// im assuming this is some frame

local a, b, c = frame.A, frame.B, frame.C;

local x1, x2 = bhask(a.Text, b.Text, c.Text); --// to get the current text, since the variable wont update on its own

frame.Result.Text = string.format("X1: %d | X2: %d", x1, x2); --// %d is a digit, so it plugs in the digits where the %d's are ```

Notice how cleaner it is. Use variables if you will be repeatedly using script.Parent.Parent, or anything really.

I'm not exactly sure what you want the result to be, but you can modify this to your needs.

Also if you read RobloxWhizYT's comment don't worry he's just being a big dum dum like always and doesn't know functions

0
Thx josestankor 39 — 5y
Ad

Answer this question