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

I know this probably has a fairly obvious answer but I can't figure it out. Can some one help me?

Asked by 8 years ago

So, I am trying to add text to a textlabel but it gives me the error: attempted to preform arithmetic on field "Text" a string value. Here is the code:

function onClicked()
    script.Parent.Parent.Parent.Parent.thingy.Text = script.Parent.Parent.Parent.Parent.thingy.Text + "bleh bleh bleh "
script.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:connect(onClicked)

2 answers

Log in to vote
0
Answered by 8 years ago

You're trying to add a string value. Adding only works with int/number values. You can set the text of the string by simply doing,

function onClicked()
    script.Parent.Parent.Parent.Parent.thingy.Text = "bleh bleh bleh " --Just make it a string value
    script.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:connect(onClicked)

If however you wanted to keep the text that's already there and just add new text to the end you would do,

function onClicked()
    script.Parent.Parent.Parent.Parent.thingy.Text = script.Parent.Parent.Parent.Parent.thingy.Text.."bleh bleh bleh "-- using two dots before the string
    script.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:connect(onClicked)

If you wanted to add the string to the beginning of the text and keep the rest you would do this,

function onClicked()
    script.Parent.Parent.Parent.Parent.thingy.Text = "Thanks Wfvj014"..script.Parent.Parent.Parent.Parent.thingy.Text -- string before the value with your "dots"
    script.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:connect(onClicked)

Hope that helped (:

Good luck!

0
It's string, why do you often write sting? Wutras 294 — 8y
0
MrHalloween I didn't catch that. User#11440 120 — 8y
0
Thats hilarious! I fixed it. I don't know why I was saying sting xD User#11440 120 — 8y
1
Thank you so much, I feel so dumb because after I read this answer, I realised that I had already done this in the past. Lol UltChowsk 85 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago
function onClicked()
    script.Parent.Parent.Parent.Parent.thingy.Text = script.Parent.Parent.Parent.Parent.thingy.Text.."bleh bleh bleh "
script.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:connect(onClicked)

Answer this question