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
1 | function onTouch() |
2 | game.Workspace:FindFirstChild( "NumValue" ).Value + 1 |
3 | end |
Help?
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.
1 | function onTouch() |
2 | game.Workspace:FindFirstChild( "NumValue" ).Value = game.Workspace:FindFirstChild( "NumValue" ).Value + 1 |
3 | end |
1 | function onTouch() |
2 | NumValue = workspace:FindFirstChild( "NumValue" ) |
3 | NumValue.Value = NumValue.Value + 1 --Set it to its own value plus 1. 1 + 1 = 2; 2 + 1 = 3; 3 + 1 = 4; etc |
4 | end |
5 |
6 | script.Parent.Touched:connect(onTouch) --Remember to connect the function! |