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

Value not changing correctly? [Solved]

Asked by
RoboFrog 400 Moderation Voter
10 years ago

I've got a tool, that when activated, will change a value to itself minus one as long as the current value is above 0. Here's the important part of the script:

local matches = game.Lighting.Hardcore.matchesleft.Value

Tool.Activated:connect(function()
    if matches > 0 then
        print("You have matches")
        matches = matches - 1
    end
end)

Alright, so, a bit of explaining --

  • The print DOES activate correctly.
  • The variable "matches" refers to an integer variable (I've also tried number to no avail)
  • I've tried removing "Value" from the variable, and hand placing it in the formula.
  • This is in a regular script, however everything else registers so I don't think it's an issue.
    • I can verify this isn't an issue, since I have now tried it.
  • I can change the value manually in game, to make sure nothing else is changing it back.

If you have any ideas as to why this isn't working, please let me know -- I see no reason why it shouldn't.

Edit: The moral here is DON'T get greedy with variable shortcuts!

0
I just tried it in a local script as well (probably should have already), and it's still printing correctly, but the value just won't change. RoboFrog 400 — 10y
1
Just an idea, but you may want to try the code in a LocalScript. RedCombee 585 — 10y
1
I agree with RedCombee, I'd try a LocalScript. Also, I would just get rid of .Value in the matches variable and put it into the anonymous function manually. I don't think the Value property would change if it's sets as a variable. Spongocardo 1991 — 10y
0
Strange, I just tried the .Value thing again, and it's now functioning. I'm always getting caught on trying to take too large a shortcut on variables. Feel free to post an "answer" and I'll accept it. RoboFrog 400 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

You probably didn't add the .Value property by hand correctly.

Try taking .Value away from the matches variable and make sure you add it by hand carefully to each instance where matches shows up in the anonymous function for the Activated event.

Ad

Answer this question