I’m making a Shop System where you can purchase Developer Products to maybe make the game have Inverted Colors, a blurry screen, or a random FOV for all players. The issue that I’m encountering is that whenever you purchase a Developer Product, (I’ll use Inverted Colors as an example), everyone’s screen goes inverted for 20 seconds, like normal. But if someone purchases it again, it adds 40 more seconds. And if they do it again it add 60 more seconds. And so on. I only want it to add 20 seconds each time. I’ve searched on Devforum for this issue but I can’t find a good source that’ll explain why I’m having this issue. Can someone help me only add 20 seconds when purchased and not duplicate every time someone buys the product?
No errors in the output.
Server Scripts
local function InvertedColors(Player)
local DefaultTime = 20
SendNotification:FireAllClients("Inverted Colors", "Purchased by: "..Player.Name)
if Lighting:FindFirstChild("InvertedColors") then
Lighting.InvertedColors.TimeLeft.Value += DefaultTime
else
local ColorCorrection = Instance.new("ColorCorrectionEffect")
local TimeLeft = Instance.new("IntValue")
ColorCorrection.Parent = Lighting
ColorCorrection.Name = "InvertedColors"
ColorCorrection.Saturation = -2
TimeLeft.Parent = ColorCorrection
TimeLeft.Name = "TimeLeft"
TimeLeft.Value += DefaultTime
repeat
TimeLeft.Value -= 1
wait(1)
until TimeLeft.Value <= 0
ColorCorrection:Destroy()
end
end
local function PlayEvent(Player, Product)
if Product == "Inverted Colors" then
InvertedColors(Player)
elseif Product == "Blur Screen" then
BlurScreen(Player)
elseif Product == "Random FOV" then
RandomFov(Player)
elseif Product == "Random Speed" then
RandomSpeed(Player)
end
end
MarketplaceService.ProcessReceipt = function(ReceiptInfo)
local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
local Product = MarketplaceService:GetProductInfo(ReceiptInfo.ProductId, Enum.InfoType.Product)
PlayEvent(Player, Product.Name)
end
Local Scripts
local function PurchaseItemSystem()
for _, Item in pairs(ScrollingFrame:GetChildren()) do
if Item.Name ~= "UIGridLayout" then
Item.CoinsPurchase.MouseButton1Click:Connect(function()
local PlayerCoins = LocalPlayer:WaitForChild("PlayerStats").Coins
local Price = Item.Coins
if PlayerCoins.Value >= Price.Value then
ChangeValue:FireServer("Coins", PlayerCoins.Value - Price.Value)
Purchase:FireServer("Coins", Price.Value, Item.Title.Text)
end
end)
Item.RobuxPurchase.MouseButton1Click:Connect(function()
MarketplaceService:PromptProductPurchase(LocalPlayer, Item.ProductID.Value)
end)
end
end
end
PurchaseItemSystem()