Why in the world is the UserId nil

  1. What do you want to achieve? Keep it simple and clear!
    I want to add money to the player’s balance when they steal the money (ProximityPrompt and ModuleScript)

  2. What is the issue? Include screenshots / videos if possible!
    The player’s UserId is either showing as ‘nil’ or as a table. Here is the code:


-- script in the ProximityPrompt

local BankSteal = require(game.ServerStorage.BankSteal)

script.Parent.Triggered:Connect(function(plr)
	
	local amount = script.Parent.ObjectText
	
	BankSteal:Steal(plr, amount)
	
end)

-- The ModuleScript that the other script is calling

local BankSteal = {}

	function BankSteal.Steal (plr, amount)
	
		local MoneyValue = game.ReplicatedStorage["MoneyValue"..tostring(plr.UserId)]
		local AmountNumber = tonumber(string.gsub(amount, "$", ""))
	
		MoneyValue.Value += AmountNumber
	
	end

return BankSteal
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried just passing along the player, and the only solution right now that I can think of would violate DRY.

I believe the player is given in the second argument. So it would be

script.Parent.Triggered:Connect(function(Obj, plr : Player)

Ok, I will try that and keep everyone updated.

1 Like

Still coming out as nil, here is the updated code:

local BankSteal = require(game.ServerStorage.BankSteal)

script.Parent.Triggered:Connect(function(plr)

	local amount = script.Parent.ObjectText

	BankSteal:Steal(amount, plr)

end)

local BankSteal = {}

	function BankSteal.Steal (amount, plr)
	
		local MoneyValue = game.ReplicatedStorage["MoneyValue"..tostring(plr.UserId)]
		local AmountNumber = tonumber(string.gsub(amount, "$", ""))
	
		MoneyValue.Value += AmountNumber
	
	end

return BankSteal

You will also need to change this:

BankSteal:Steal(amount, plr)

to this:

BankSteal.Steal(amount, plr)

Wait you didn’t even put the player param as the 2nd one, it’s still the first.

I don’t understand what you mean by that

The way you’re calling it is trying to pass self with :Steal, you need to do .Steal

In your proximity prompt script. You should change it to this.

script.Parent.Triggered:Connect(function(Obj, plr)