After multiple times having the same problem I need to ask everyone if y’all do to, I can’t be the only one having it.
Basically, when I try to modify let’s say for example a number value.
local nvalue = game.Workspace.NumberValue.Value
nvalue = 1
Sometimes, the code will run perfectly fine, but after some time it simply doesn’t change the number value anymore when it’s ran, and it can only be fixed if I remove the .Value from the variable and add it to the script itself
local nvalue = game.Workspace.NumberValue
nvalue.Value = 1
I don’t know how to replicate this glitch but it keeps happening to me and it makes my scripting time more difficult and sometimes makes me rewrite an entire code just to remove .Value from the variable and add it to the script itself. Note that, no changes are made to the script before it breaks, it’s literally the same as before. I’ve been searching through the web and never seen anyone have this problem before. The value simply does not replicate.
This isn’t really a glitch, nor a bug. It’s just a common mistake that many beginners make.
The thing is, when you do
local nvalue = game.Workspace.NumberValue.Value
You’re not saving a reference to the property, meaning you can go at any time and do this
nvalue = 1
It’s saving the value that property was set to. If NumberValue.Value was 25, you can print(nvalue) and you’ll see that it prints 25. When you do nvalue = 1, you’re pretty much doing 25 = 1, which will obviously error.
I never stopped to think of that and now I’m feeling very stupid, is there any faster way to change the value of something without having to type the .Value? Also, I may have never noticed this error because everything works just fine but after sometime it just doesn’t. Thanks for helping me out tho.
Alright, thank you very much, I can finally stop slamming my head on the wall, I’ll delete the topic right after this reply cause this was my most stupid question so far.
It’s fine really, we all make mistakes. The thing is if we’re scared to ask about our mistakes, we’ll never get an answer to them, we’ll carry on with those mistakes.