I've got a "cash exchange system" you type in the amount of cash that you want to give to someone, then press a button. It puts a bag in your inventory with the amount of money that you put in the text box. The only problem is that I cant get the amount of money that is suppose to be put in the bag with filtering enabled on. I get the error : attempt to index a nil value. When I try to get the amount in a server script. Here is the code:
Local script (in gui):
local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local text = script.Parent.Parent.AmountBox
local Amount = tonumber(text.Text)
if Player.Stats.Beli.Value >= Amount and Amount ~= 0 and Amount > -1 then
script.Parent.Parent.Parent.Parent.UI_Click:Play()
Player.Backpack.BeliClicked:FireServer()
elseif Player.Stats.Beli.Value < Amount or Amount ~= 0 or Amount > -1 then
script.Parent.Parent.Parent.Parent.UI_Error:Play()
end
end)
Server sided script(in backpack):
script.Parent.BeliClicked.OnServerEvent:Connect(function(Player)
local text = Player.PlayerGui:FindFirstChild("Main"):FindFirstChild("DropBeli"):FindFirstChild("AmountBox") --error comes from here
local Amount = tonumber(text.Text)
script.value.Value = Amount
if Player.Stats.Beli.Value >= script.value.Value then
Player.Stats.Beli.Value = Player.Stats.Beli.Value - script.value.Value
local bag = game.ReplicatedStorage.Items.MoneyBag:Clone()
bag.Handle.Amount.Value = script.value.Value
bag.Parent = Player.Backpack
bag.ToolTip = (script.value.Value)
end
end)

3 comments
I don't think you can put server scripts into backpack. I reccoment putting it in serverscriptservice and putting the remote event into replicated storage. Also you shouldn't change guis through server, you need to fire client.
The server can never see what is inside the PlayerGui of a player, even if it is passed through. I would suggest passing the Amount through the client. Something like (Player.Backpack.BeliClicked:FireServer(text.Text)). You should put the RemoteEvent in ReplicatedStorage though and make it (game.ReplicatedStorage.BeliClicked:FireServer(text.Text))
Thanks, zyrun. Also, @Earthkingiv. You can put server scripts and remote events in the backpack.