Is there a way to detect changes in a GlobalDataStore?

In my game I have a few chests spread around the map that allow users to see how many people made a donation to the game, and allows them to also donate 10 robux too (bit cheesy way to make some extra R$ I know)

Anyway I was wondering if it’s possible to detect a change in the DataStore that would fire everytime it’s updated, instead of having a constant loop watching for it. This is my current code (some functions/variables may not be defined for space’s sake)

local DS = game:GetService("DataStoreService"):GetDataStore("2PMT")
local notif = game.ReplicatedStorage:WaitForChild("Remote"):WaitForChild("SystemMessage")
local Raised = DS:GetAsync(CurrencyType.."_Raised")
game:GetService("RunService").Heartbeat:Connect(function() --- here's the loop
	wait(1)
	for model,chest in pairs(script.Parent:GetChildren()) do
		if chest:IsA("Model") then
			chest.Screen.SurfaceGui.Raised.ROBUX.Text = CurrencyType.." "..Raised
			chest.Screen.CD.MouseClick:connect(function(Player)
				if Debounce == false then
					Debounce = true
					if Player.userId > 0 then
						MS:PromptProductPurchase(Player,ProductID)
					end
					wait(2)
					Debounce = false
				end
			end)
		end
	end
end)
MS.PromptProductPurchaseFinished:connect(function(UserId,Id,IsPurchased) --- updates the datastore
	if IsPurchased and Id == ProductID then
		DS:IncrementAsync(CurrencyType.."_Raised",ProductPrice)
		local Player = Players:GetPlayerByUserId(UserId)
		---DS:OnUpdate(CurrencyType.."_Raised",PrintOut)
		notif:FireClient(Player,"Thank you for donating, "..Player.Name.. "!",Enum.FontSize.Size10,Enum.Font.SourceSansItalic,Color3.fromRGB(255, 255, 10))
		play_Sound(Player,"Buy",2)
		if Player:FindFirstChild("Donator") == false then
			local dohn = Instance.new("Model")
			dohn.Name = "Donator"
			dohn.Parent = Player
		end
	end
end)

Instead of watching for a change in the datastore couldn’t you use messaging service? That way you only have to query the datastore once at the beginning and then you could hook up an event and fire it inside the PromptProductPurchaseFInished to signal someone bought it.

Would that event still fire and update the count seen on the model when a purchase was done on another server?

The MessagingService allows game servers in the same game to communicate with each other in real time (< 1 second) using topics. Topics are developer defined strings (1-80 characters) that game servers can send and receive messages.
Delivery is best effort and not guaranteed. Make sure to architect your game so delivery failures are not critical.

As long as you have subscribed every server to the topic and fired the topic every time someone buys it then yes it would send the message to every server. Of course there can be failures so I’d still suggest querying the datastore to make sure it is the right amount every once in a while.