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

How to change an object IntValue's value with a script?

Asked by 4 years ago
Edited 4 years ago

Here is my code:

--Variables

local Drill = script.Parent
local DrillUpper = Drill:FindFirstChild("Drill upper")
local DrillTransparency = DrillUpper.Transparency
local Money = Drill.parent.parent:FindFirstChild("CurrencyToCollect")

--Variables

--Testing

print (DrillUpper.Name)
print (Drill.Name)
print (Money)
print (DrillTransparency)

--Testing

--Function

local function TransparencyTest()
    print ("function works")
    wait (2)
    if DrillTransparency == 0 then
        while (true) do
            Money.value = Money.value + 1 

            print (Money)
            wait(1)
        end
    end
end

--Function

--The program

TransparencyTest()

--The program

Why doesn't the object variable change?
It is no errors.
I saw im am not the only one having problems with this, but they deleted the code so I didn't understand it fully.

2
Is the IntValue you are trying to change 'Money'? If so, a common mistake is to forget to access the Value property when updating IntValue values. Just use Money.Value instead. e.g. Money.Value = Money.Value + 1 123marble 61 — 4y
0
@123marble that's the answer, put it as an answer so someone else doesn't MachoPiggies 526 — 4y
0
No I am not trying to change Money. I am trying to change CashToCollect object that is in the workspace. I have a variable in the upper section. Disnejar 2 — 4y
0
CashToCollect is assigned to the Money variable though? DeceptiveCaster 3761 — 4y
View all comments (3 more)
0
yes Disnejar 2 — 4y
0
Use an if statement and a print() to see if Money is not nil. DeceptiveCaster 3761 — 4y
0
I have tried and Money isn't nil. I just need help to change CashToCollect that is an int variable OBJECT. Money is just a variable I used in the script, if I need to delete it i will do it. Disnejar 2 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

All I can really see is on line 26, you have Money.value, capitalization really matters, so make sure to change anywhere it says .value, to .Value. The V in Value always has to be capital.

Also, make sure when you run the game, the DrillTransparency is set to 0.

0
thank you very much Disnejar 2 — 4y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

"Is the IntValue you are trying to change 'Money'? If so, a common mistake is to forget to access the Value property when updating IntValue values. Just use Money.Value instead. e.g. Money.Value = Money.Value + 1".

Yeah, that's the correct answer, so it might work like this, change the line 26 become this:

Money.Value = Money.Value + 1

If it worked, mark this as the correct answer, also thanks for 123marble too.

0
It didn't work Disnejar 2 — 4y

Answer this question