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

How would I change the name of a block using math?

Asked by 8 years ago

So I'm working on a basic little script, learning the basics of Lua math.

number1 = script.Parent.Name;   --The name is 0
number2 = 1;
number3 = 10;
number4 = 40;

function onTouched(hit)
    print(number1+number2) 
    script.Parent.Name = (number1+number2)
    wait()
end

script.Parent.Touched:connect(onTouched)

This is where I am at now, is there a simpler way to do this? When I go to test this, It only goes to 1, and when I go to touch it again it still gives me 1.

1 answer

Log in to vote
0
Answered by 8 years ago
number2 = 1;
number3 = 10;
number4 = 40;

function onTouched(hit) 
number1 = script.Parent.Name -- if this was out side then the name wouldnt update since the code only gets refreshed in the function
    print(number1+number2) 
    script.Parent.Name = (number1+number2)
    wait()
end

script.Parent.Touched:connect(onTouched)

0
accept and +1 if it works! User#5978 25 — 8y
0
Don't have enough rep to +1 you, I would though. Mentalcase 35 — 8y
0
Im pretty sure "number1 = script.Parent.Name" is a string and not a number, you shouldn't be able to add them up unless Roblox turns it into a number automaticly. Turgon 80 — 8y
Ad

Answer this question