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

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

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

✓ Accepted answer
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)

3 comments

0

accept and +1 if it works!

0

Don't have enough rep to +1 you, I would though.

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.

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