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

I cant add to a value?

If I want to add 1 to a NumValue when a part is touched, but its not working

Can someone help please?

This is what I have so far

function onTouch()
	game.Workspace:FindFirstChild("NumValue").Value +1
end

Help?

2 answers

It's not working because there's nothing telling the script that +1 is the value that needs to be added.

Additionally, ''Value = +1'' won't work either, because +1 is not a valid numerical assignment in logical mathematics. However, we can use those mathematics after we've already assigned a valid numerical; Therefore, we need to set the value to itself plus 1 to get the desired effect.

function onTouch()
    game.Workspace:FindFirstChild("NumValue").Value = game.Workspace:FindFirstChild("NumValue").Value + 1
end

1 comment

1

And you have to connect the function.

function onTouch()
	NumValue = workspace:FindFirstChild("NumValue")
	NumValue.Value = NumValue.Value + 1 --Set it to its own value plus 1. 1 + 1 = 2; 2 + 1 = 3; 3 + 1 = 4; etc
end

script.Parent.Touched:connect(onTouch) --Remember to connect the function!

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