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)
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
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.
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