Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Value doesn't change?

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

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!

4 comments

0

Didn't work. InternalCash didn't change it's value.

0

Sorry, i forgot to put .Value on line 8, but it's fixed now

0

ugh still didn't work

0

Where is "InternalCash" located?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.