I’m making a script which fires whenever a player purchases a product from a GUI shopping panel however the script only fires roughly 25% of the time (when it’s supposed to fire all the time)
Here is a video showcasing the (lack of) action of the script
And here is the full code
local marketPlaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local GUI = game:GetService("StarterGui")
marketPlaceService.ProcessReceipt = function(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if receiptInfo.ProductId == 1658627474 then
player.leaderstats.Stage.Value += 1
wait(1)
player:LoadCharacter()
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1659261655 then
local playername = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
for _, p in pairs(players:GetPlayers()) do
p.leaderstats.Stage.Value += 1
wait(1)
p:LoadCharacter()
local TextLabel = Instance.new("TextLabel")
TextLabel.Parent = p.PlayerGui.Default
TextLabel.Text = p.Name .. " has skipped everyone's stage!"
TextLabel.FontFace = Font.fromName("FredokaOne")
TextLabel.TextScaled = true
TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
TextLabel.TextColor3 = Color3.new(158, 0, 0)
TextLabel.Visible = true
wait(5)
TextLabel.Visible = false
end
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1660050340 then
local playername = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
for _, p in pairs(players:GetPlayers()) do
if p.Name ~= playername then
if p.Character.HumanoidRootPart then
p.leaderstats.Stage.Value -= 1
wait(1)
p:LoadCharacter()
end
end
local TextLabel = Instance.new("TextLabel")
TextLabel.Parent = p.PlayerGui.Default
TextLabel.Text = p.Name .. " has undone everyone's stages!"
TextLabel.FontFace = Font.fromName("FredokaOne")
TextLabel.TextScaled = true
TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
TextLabel.TextColor3 = Color3.new(158, 0, 0)
TextLabel.Visible = true
wait(5)
TextLabel.Visible = false
end
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1658851386 then
for _, p in pairs(players:GetPlayers()) do
if p ~= player then
if p.Character.HumanoidRootPart then
local explosion = Instance.new("Explosion")
explosion.Position = CFrame.new(p.HumanoidRootPart.Position)
end
end
local TextLabel = Instance.new("TextLabel")
TextLabel.Parent = p.PlayerGui.Default
TextLabel.Text = player.Name .. " has nuked the server!"
TextLabel.FontFace = Font.fromName("FredokaOne",Enum.FontWeight.Medium,Enum.FontStyle.Normal)
TextLabel.TextScaled = true
TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
TextLabel.TextColor3 = Color3.new(158, 0, 0)
TextLabel.Visible = true
wait(5)
TextLabel.Visible = false
end
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1660053718 then
for _, p in pairs(game.Players:GetPlayers()) do
if p ~= player then
p.PlayerGui.Default.Blinded.Visible = true
end
local TextLabel = Instance.new("TextLabel")
TextLabel.Parent = p.PlayerGui.Default
TextLabel.Text = player.Name .. " has blinded everyone for 60s!"
TextLabel.FontFace = Font.fromName("FredokaOne")
TextLabel.TextScaled = true
TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
TextLabel.TextColor3 = Color3.new(158, 0, 0)
TextLabel.Visible = true
wait(5)
TextLabel.Visible = false
wait(55)
for _, p in pairs(game.Players:GetPlayers()) do
p.PlayerGui.Default.Blinded.Visible = false
end
end
GUI.Default.Blinded.Visible = true
wait(60)
GUI.Default.Blinded.Visible = false
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1660090129 then
for _, p in pairs(game.Players:GetPlayers()) do
if p ~= player then
if p.Character and p.Character:FindFirstChild("HumanoidRootPart") then
local Humanoid = p.Character.Humanoid
Humanoid.WalkSpeed = Humanoid.WalkSpeed / 2
wait(60)
Humanoid.WalkSpeed = 16
end
end
local TextLabel = Instance.new("TextLabel")
TextLabel.Parent = p:WaitForChild("PlayerGui"):WaitForChild("Default")
TextLabel.Text = player.Name .. " has slowed everyone down for 60s!"
TextLabel.FontFace = Font.fromName("FredokaOne")
TextLabel.TextScaled = true
TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
TextLabel.TextColor3 = Color3.new(158, 0, 0)
TextLabel.Visible = true
wait(5)
TextLabel.Visible = false
TextLabel:Destroy()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1660098210 then
for _, p in pairs(game.Players:GetPlayers()) do
if p.Character and p.Character:FindFirstChild("HumanoidRootPart") then
local Humanoid = p.Character.Humanoid
Humanoid.WalkSpeed = Humanoid.WalkSpeed * 2
wait(60)
Humanoid.WalkSpeed = 16
end
local TextLabel = Instance.new("TextLabel")
TextLabel.Parent = p:WaitForChild("PlayerGui"):WaitForChild("Default")
TextLabel.Text = player.Name .. " has sped everyone up for 60s!"
TextLabel.FontFace = Font.fromName("FredokaOne")
TextLabel.TextScaled = true
TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
TextLabel.TextColor3 = Color3.new(158, 0, 0)
TextLabel.Visible = true
wait(5)
TextLabel.Visible = false
TextLabel:Destroy()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1660096890 then
game.Workspace.Gravity = 196.2 / 6
for _, p in pairs(game.Players:GetPlayers()) do
local TextLabel = Instance.new("TextLabel")
TextLabel.Parent = p:WaitForChild("PlayerGui"):WaitForChild("Default")
TextLabel.Text = player.Name .. " has reduced the gravity for 60s!"
TextLabel.FontFace = Font.fromName("FredokaOne")
TextLabel.TextScaled = true
TextLabel.Size = UDim2.new(0.25, 0, 0.25, 0)
TextLabel.Position = UDim2.new(0.375, 0, 0.386, 0)
TextLabel.TextColor3 = Color3.new(158, 0, 0)
TextLabel.Visible = true
wait(5)
TextLabel.Visible = false
TextLabel:Destroy()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
What fix should I make to make it so that the “receipt” actually gets processed and the script gets triggered?