Value does not change properly

I’m trying to make a system where certain things cause a number value to change using this script

local value = script.Parent.Value
local data = workspace.PurchasedItemsForData

cashdrop = 1

function updateValue()
	value = cashdrop
end

if data.CoolHat.Value == true then
	cashdrop += 3
	updateValue()
end

if data.MsFloppa.Value == true then
	cashdrop = cashdrop * 2
	updateValue()
end

if data.HomieSogga.Value == true then
	cashdrop = cashdrop * 2
	updateValue()
end

if data.CatnipPlant.Value == true then
	cashdrop = cashdrop * 4
	updateValue()
end

if data.TheRock.Value == true then
	cashdrop = cashdrop * 3
	updateValue()
end

if data.TBH.Value == true then
	cashdrop = cashdrop * 4
	updateValue()
end

(Most names that you might recognize are simply names I used to easily associate those objects and never really changed)
Now other scripts call for this cashdrop value like this:

local person = game.Players:FindFirstChild(plr.Name)
local cashdrop = script.CashDrop.Value
person.leaderstats.Cash.Value += cashdrop

And the layout is always this, script with the value inside, and the cashdrop handler inside the value (Whoops, I showed the layout of a different script than the one I showed, but you can figure how it’d change)
image
I don’t recieve any errors, it just doesn’t change the value at all, I’ve changed this script several times and it still does not change the value at all, I’ve never really done these kinds of value changing scripts so if I did something wrong I’d like to know what and how to avoid doing it again.

Instead of using a function, edit the value directly:

value = 3

Is the same as:

script.Parent.Value = 3

EDIT —
I noticed something else. Your script runs once without a loop, which is most definitely the source of your issue. Add a loop to keep it going:

game:GetService("RunService").RenderStepped:Connect(function()
	if data.CoolHat.Value == true then
		cashdrop += 3
		updateValue()
	end
	
	if data.MsFloppa.Value == true then
		cashdrop = cashdrop * 2
		updateValue()
	end
	
	if data.HomieSogga.Value == true then
		cashdrop = cashdrop * 2
		updateValue()
	end
end)

Where is everything located?

It locates itself in 3 different parts, all of them have the same layout, two are within a script, one of those scripts is in serverscriptservice and the other is inside a part inside a model in workspace, the other one is just inside a mesh inside the lighting (said mesh gets cloned into workspace through other scripts).

I tried both but the value still doesn’t change, loop or no loop, function or direct change, value remains at the default 1 (Which I doubt comes from the script).

Ok, I didn’t notice the rest of the code below, and that might be the issue. Unless, you changed it. But, here’s a rewrite that should work. If it doesn’t, then it’s an issue with other scripts or variables:

local value = script.Parent.Value
local data = workspace.PurchasedItemsForData

cashdrop = 1 --idk if this was predefined but i'd put a local here if not

while task.wait() do
	if data.CoolHat.Value then
		cashdrop += 3
		value = cashdrop
	end
	
	if data.MsFloppa.Value then
		cashdrop = cashdrop * 2
		value = cashdrop
	end
	
	if data.HomieSogga.Value then
		cashdrop = cashdrop * 2
		value = cashdrop
	end
	
	if data.CatnipPlant.Value then
		cashdrop = cashdrop * 4
		value = cashdrop
	end
	
	if data.TheRock.Value then
		cashdrop = cashdrop * 3
		value = cashdrop
	end
	
	if data.TBH.Value then
		cashdrop = cashdrop * 4
		value = cashdrop
	end
end

Another thing to add. Make sure you’re using the right datatypes! If you check for a bool and your value is a number, your if statement will not run as expected!

What I’m trying to do using the if checks is to see if those values are true and applying the corresponding change to the cashdrop. Following what you did here still did not change the value so I’m going to see if anything else is wrong, since I find it weird that while doing this I’ve recieved no errors and it’s just the script not doing anything, I appreciate the help and I’ll mark this as a solution.

1 Like

I have solved the issue by just not using a physical value, just using the cashdrop value within the same script that calls for it. Your script worked, it just wasnt used in the correct place.