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

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

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

✓ Accepted answer

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!

4 comments

0

It's string, why do you often write sting?

0

MrHalloween I didn't catch that.

0

Thats hilarious! I fixed it. I don't know why I was saying sting xD

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

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)

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