Attempt to index nil with 'FindFirstChild'

It makes the script shorter and easier to read but I don’t know why, I don’t recieve anything

1 Like

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.

1 Like
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.

1 Like

I got this
image

1 Like

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

2 Likes

But it has a value…
image
How is that possible?

1 Like

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?

1 Like

Don’t change values in StarterGui. They’re replicated to the player when they join.

3 Likes

Okay so I changed my script and put it in Workspace but now I have the error:
image

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)
1 Like

LocalPlayer only exists within LocalScripts. Also, don’t put these kinds of scripts in the Workspace.

Also, what’s the loop for? I’m very sure you don’t need it.

1 Like

Is the Folder’s name leaderstats?

If no, add it.
If yes, it might be a bug. Or change it to :WaitForChild("leaderstats").

1 Like

Because it updates depending on a stat a player has called Multiplier, and it changes in the game. So the formula has to update every time

1 Like

Yes it is, the problem doesn’t come around here apparently

1 Like

Then use RunService instead of yielding the whole script with a loop

1 Like

Okay, by the way you said that I shouldn’t put these types of script in the Workspace, then where do you think I should put them?

1 Like

It doesn’t actually matter. You can put it in ServerSctiptService, but it’s purely aesthetic.

1 Like

small correction, I’d avoid placing scripts in workspace unless they really need to, simply because most scripts don’t need to be replicated to the client. (the name, classname etc, i am aware source isnt replicated)

1 Like

Okay so I took the advice of everyone but I’m facing an issue.
The script doesn’t give the cash to the player but it works, basically I tell the script to give cash depending on a numbervalue placed in the Workspace, but I don’t know why, this number value is equal to 0 for the game. Lemme show you:

I made a script that print’s the NumberValue’s Value:
print(game.Workspace["Usefull Informations"].DevProducts.Cash.Cash1.Value)

And here is the number value in game:

It prints out 0, I don’t know why. How could I fix that?

1 Like

Could you send your scripts as they currently are and I’ll give you the fix? Just so I don’t need to piece together what changes have/haven’t been made.


It won’t really be replicated to the client. The ‘Script’ object will, but only as a hollow shell comprised of a Name, ClassName, LinkedSource, and Disabled property. It will take up so little data that it won’t matter. The source of the script (which takes up far more space) won’t be replicated because server side script sources are never sent to the client.

1 Like

I made a new topic that covers my new problem here: Printing out a NumberValue that changes doesn't work - #4 by FlyingFrets

2 Likes