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

adding number then add another number with , ?

Asked by 9 years ago

i click the button then the testvalue = 5 then i click it again and its suppose to be testvalue = 5,5

03:20:21.555 - Players.Player.PlayerGui.ScreenGui.LocalScript:5: attempt to perform arithmetic on a string value 03:20:21.556 - Stack Begin 03:20:21.558 - Script 'Players.Player.PlayerGui.ScreenGui.LocalScript', Line 5 03:20:21.559 - Stack End

script.Parent.TEST.MouseButton1Up:connect (function ()
    if script.Parent.testvalue.Value == 0 then
        script.Parent.testvalue.Value = script.Parent.testvalue.Value + (script.Parent.TEST.Text)
    else
        script.Parent.testvalue.Value = script.Parent.testvalue.Value + (","..script.Parent.TEST.Text)
    end 
end)

3 answers

Log in to vote
-1
Answered by 9 years ago

It thinks you are trying to perform math on the string "," And i dont get what you want to do with it, please explain

Ad
Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

You're trying to use + on a string, ",". Unlike JavaScript, Lua does not use the plus sign for concatenation, so you'll get an error.


Looking at your explanation carefully, I can see that you don't actually add anything to any number. You just want to add a comma, then put the same number there again, 5,5.

My solution is to not use numbers at all, but to stick with strings, since you don't even need to do any math. Is pseudo code, it would look something like this;

local num = "0"

if num == "0" then
    num = "5"
else
    num = num..", 5"
end
Log in to vote
-3
Answered by
xuefei123 214 Moderation Voter
9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

script.Parent.TEST.MouseButton1Up:connect (function () if script.Parent.testvalue.Value == 5 then script.Parent.testvalue.Value = script.Parent.testvalue.Value = 5 .. script.Parent.testvalue.Value else script.Parent.testvalue.Value = script.Parent.testvalue.Value + (","..script.Parent.TEST.Text) end end)

0
Remember explain better I think thats what you want but explain better. xuefei123 214 — 9y
0
this doesnt work and the default value is 0 Layfonex 0 — 9y
0
ok xuefei123 214 — 9y

Answer this question