Number value changed doesnt fire

hi in my script i have 2 event listeners but for some reason most of the times, the data async function only runs and the other doesnt.


	
	Gold.Changed:Connect(function(value)
		print("goldchange")
		if prevGold then
			print("prevExists")
			local infoTable = {PlayerInstance = Player,
				PrevAmount = prevGold,
				NewAmount = value,
				Difference = math.abs(prevGold - value),
				Image = goldUI.GoldImage,
				StorageIcons = nil,
				GoldValueVar = goldUI.GoldValue
			}

			goldUI.GoldValue.Value = prevGold
			prevGold = value

			if value < infoTable.PrevAmount then

				print("prevgolexists")

				local clonesIcon = Instance.new("Frame",Player.PlayerGui.GoldCurrency)
				clonesIcon.Name = "Gold"
				clonesIcon.Size = UDim2.fromScale(1,1)
				clonesIcon.Transparency = 1

				infoTable.StorageIcons = clonesIcon
				goldUI.GoldValue.Value = infoTable.PrevAmount

				generatingIcons(infoTable)
				
				if not cooldownAnim then
					cooldownAnim = true
					counting(infoTable, goldUI)
					cooldownAnim = false
				else 
					
					goldUI.TextLabel.Text = value
				end
				
			else

				counting(infoTable)

			end

		else
			print("noPrev")
			prevGold = value
		end
	end)
	
	Gold.Changed:Connect(function(value)
		DataStoreGold:SetAsync(Player.UserId, Player.leaderstats.Gold.Value)
	end)
	

image

as u can see, only the last listener runs and i tried changing positions.

1 Like

Have you tried to only use one of them?
I don’t see any reason to use twice the same event for the same currency.

Gold.Changed:Connect(function(value)
     print("goldchange:",value)
	--do stuff here
end)

Also, you shouldn’t really save the currency like that, it’ll be too many requests and inefficient.

1 Like

Have you tried using :GetPropertyChangedSignal("Value")

1 Like

hi everyone i think i realized the problem, which is that the player folders are getting duplicated idk how

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.