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

Value doesn't change?

Asked by 9 years ago
script.Parent.Touched:connect(function(hit)
    local h = hit
    local ca = h:FindFirstChild("Cash")
    if ca then
        local civ = script.Parent.Parent.Parent.Parent.Values.InternalCash.Value
        if civ then
            local cav = ca.Value
            civ = civ +cav
        end
    end
end)

No errors occur, but nothing happens.

2 answers

Log in to vote
1
Answered by 9 years ago

You had some mistakes, and I explained every single one to the best of my ability.

script.Parent.Touched:connect(function(hit)
    -- no need for local h
    local ca = hit.Parent:findFirstChild("Cash") -- hit is the part that touched, the value is in the character, so you have to do hit.Parent
    if ca then
        local civ = script.Parent.Parent.Parent.Parent.Values.InternalCash -- defining something with ".Value" won't work
        if civ then
            -- no need for local cav, just use ca 
            civ.Value = civ.Value + ca.Value
        end
    end
end)

Hope it helps!

0
Didn't work. InternalCash didn't change it's value. connieoop 10 — 9y
0
Sorry, i forgot to put .Value on line 8, but it's fixed now AbsoluteAxiom 175 — 9y
0
ugh still didn't work connieoop 10 — 9y
0
Where is "InternalCash" located? AbsoluteAxiom 175 — 9y
Ad
Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

As absolute pointed out, line 5 is a problem. But why? Well, when you make a variable equal to a property, no reference to the original object is retained. This means that editing the variable later will not change the property, and if the property changes, the variable will not change with it. The variable will become equal to the value of the property, but it won't actually affect the object.

Therefore, make your variables equal to object. Then you can use the properties, as absolute showed you.

Answer this question