Dev product perk looping?

So I’ve made dev products, which will change the color of all LEDs in the game. However, the color change will keep looping to what a certain player has last purchased, until a new color has been bought, even when a new server is created (only if the purchaser joins, though). Why is this happening?

local marketplace = game:GetService("MarketplaceService")

marketplace.ProcessReceipt = function(receiptInfo)	
wait(1)			
---RED---
	
	if receiptInfo.ProductId == 1264139376 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(190, 104, 98)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(190, 104, 98)
				v.BrickColor = BrickColor.new(338)
			end
		end
		
---ORANGE---	
		
	elseif receiptInfo.ProductId == 1264139431 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(204, 142, 105)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(204, 142, 105)
				v.BrickColor = BrickColor.new(18)
			end
		end
		
---YELLOW---		
		
	elseif receiptInfo.ProductId == 1264139472 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(199, 172, 120)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(199, 172, 120)
				v.BrickColor = BrickColor.new(352)
			end
		end
		
---GREEN---		

	elseif receiptInfo.ProductId == 1264139510 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(124, 156, 107)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(124, 156, 107)
				v.BrickColor = BrickColor.new(317)
			end
		end
		
---BLUE---		
		
	elseif receiptInfo.ProductId == 1264139549 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(0, 66, 174)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(82, 124, 174)
				v.BrickColor = BrickColor.new(305)
			end
		end
		
---PURPLE---

	elseif receiptInfo.ProductId == 1264139611 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(98, 37, 209)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(98, 37, 209)
				v.BrickColor = BrickColor.new(1031)
			end
		end
		
---PINK---	
		
	elseif receiptInfo.ProductId == 1264139649 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(255, 102, 204)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(255, 102, 204)
				v.BrickColor = BrickColor.new(1016)
			end
		end
		
---WHITE---
		
	elseif receiptInfo.ProductId == 1264139717 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(202, 203, 209)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(202, 203, 209)
				v.BrickColor = BrickColor.new(320)
			end
		end
		
---BLACK---

	elseif receiptInfo.ProductId == 1264139752 then
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'Light' then
				v.SpotLight.Color = Color3.fromRGB(27, 42, 53)
			end
		end
		for i, v in pairs (game.Workspace.LEDs:GetChildren()) do
			if v.Name == 'LED' then
				v.SurfaceLight.Color = Color3.fromRGB(27, 42, 53)
				v.BrickColor = BrickColor.new(26)
			end
		end
	else
		print("??")
	end
end
1 Like

First of all you have to verify the code inside ProcessReceipt doesn’t and can’t error. If the code inside ProcessReceipt errors your script will attempt to reward the player each time they join until it doesn’t. Also when handling dev products you have to return Enum.ProductPurchaseDecision.PurchaseGranted if the purchase was successful and Enum.ProductPurchaseDecision.NotProcessedYet if there was an error.

1 Like