So, I got an error on my script for developer products. I can’t manage to fix it, here’s the script:
local MarketplaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local SG = game:GetService("StarterGui")
local productID = 1347531300
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
local cash = game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Cash")
cash += SG.Utilities.UIs.ShopMain.InFrame.ButtonsFrame.Cash.Shadow1.BuyButton1.InfoLabel.ChangeGiveCash.GiveCash.Value
end
end
MarketplaceService.ProcessReceipt = processReceipt
Attempt to index nil means you are trying to access a property of nil, aka one of the FindFirstChild’s is returning nil, or game.Players.LocalPlayer is nil. There is no point in using FindFirstChild if you have no regard for what it returns.
also are you trying to process receipts on the client???
local players = game:GetService("Players")
local SG = game:GetService("StarterGui")
local productID = 1347531300
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
game.Players.PlayerAdded:Connect(function(player)
local cash = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
cash.Value += SG.Utilities.UIs.ShopMain.InFrame.ButtonsFrame.Cash.Shadow1.BuyButton1.InfoLabel.ChangeGiveCash.GiveCash.Value
end)
end
end
MarketplaceService.ProcessReceipt = processReceipt
My goal for this script is to make a developer product for a simulator that is going to give me a certain amount of cash that is set in a NumberValue.
I have no errors in the output but this doesn’t seem to work.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local StarerGui = game:GetService("StarterGui")
local productID = 1347531300
local function ProcessReceipt(ReceiptInfo)
local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
if not Player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
Player.leaderstats.Cash.Value += StarerGui.Utilities.UIs.ShopMain.InFrame.ButtonsFrame.Cash.Shadow1.BuyButton1.InfoLabel.ChangeGiveCash.GiveCash.Value
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = ProcessReceipt
I wouldn’t recommend having having a wide list of indexing though such as StarerGui.Utilities.UIs.ShopMain.InFrame.ButtonsFrame.Cash.Shadow1.BuyButton1.InfoLabel.ChangeGiveCash.GiveCash.Value
it damages the codes readability
On line 14, replace the game.Players.LocalPlayer with game.Players:GetPlayerByUserId(receiptInfo.PlayerId). I’m assuming this script is a server script since it is located in the ServerScriptStorage, and accessing local players from there usually cause problems.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local StarerGui = game:GetService("StarterGui")
local productID = 1347531300
local function ProcessReceipt(ReceiptInfo)
print("Proccessing reciept")
local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
if not Player then
warn("Player is not ingame, not yet proccessed payment")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
print(string.format("%s has %i cash, incrimenting by %i", Player.Name, Player.leaderstats.Cash.Value, StarerGui.Utilities.UIs.ShopMain.InFrame.ButtonsFrame.Cash.Shadow1.BuyButton1.InfoLabel.ChangeGiveCash.GiveCash.Value))
Player.leaderstats.Cash.Value += StarerGui.Utilities.UIs.ShopMain.InFrame.ButtonsFrame.Cash.Shadow1.BuyButton1.InfoLabel.ChangeGiveCash.GiveCash.Value
print("Purchase granted")
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = ProcessReceipt
Try this and look at your output and tell me what it spat out.
Well then, clearly the reason why your cash is not changing is because StarerGui.Utilities.UIs.ShopMain.InFrame.ButtonsFrame.Cash.Shadow1.BuyButton1.InfoLabel.ChangeGiveCash.GiveCash.Value equals 0
It’s not equal to 0, but, when I changed the script with something else like Player.leaderstats.Cash.Value += Player.leaderstats.Cash.Value
then it worked.
So i think the problem is that the game doesn’t read a number value in the Starter GUI?
Okay so I changed my script and put it in Workspace but now I have the error:
Here’s the script:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function()
while wait(.5) do
local formula = ((game.Players.LocalPlayer.leaderstats.Multiplier.Value/1.5)*game.Workspace.ServerMulti.OldValue.Value*5)/10 -- Multi.Value * ServerMultiplier * EventMultiplier/10
if game.Workspace["Usefull Informations"].PlayerInformations.VIP.Value == true then
formula = formula*5
end
script.GiveCash.Value = formula*100*(3600/2)
end
end)