Cant Find Value

This in ServerScriptService ↓ (Script)

game.ReplicatedStorage.WithDraw1.OnServerEvent:Connect(function(player)


	local plr = player:WaitForChild("PlayerGui")

	local TextBoxC1 = plr:WaitForChild("ATM1"):FindFirstChild("putamont1")
	local Depo = plr:WaitForChild("ATM1"):FindFirstChild("DEPOSIT1")
	local With = plr:WaitForChild("ATM1"):FindFirstChild("WITHDRAW1")

	local amountToWithdraw = tonumber(TextBoxC1.Text)
	local creditCardValue = player:WaitForChild("CreditCardValue"):WaitForChild("CreditCard1").Value

	if amountToWithdraw and creditCardValue then
		if amountToWithdraw > 0 and amountToWithdraw <= creditCardValue then
			-- Subtract the amount from the credit card value
			player.CreditCardValue.CreditCard1.Value = creditCardValue - amountToWithdraw
			-- Add the withdrawn amount to the player's Moneys value
			player.leaderstats.Moneys.Value = amountToWithdraw + player.leaderstats.Moneys.Value
		else
			-- Handle the case where the withdrawal amount is invalid
			print("Invalid withdrawal amount")
		end
	else
		-- Handle the case where the input is not a valid number or creditCardValue is nil
		print("Invalid input or credit card value is nil")
	end
end)

game.ReplicatedStorage.Deponsit1.OnServerEvent:Connect(function(player)

	local plr = player:WaitForChild("PlayerGui")



	local TextBoxC1 = plr:WaitForChild("ATM1").putamont1
	local Depo = plr:WaitForChild("ATM1").DEPOSIT1
	local With = plr:WaitForChild("ATM1").WITHDRAW1



	local amountToWithdraw = tonumber(TextBoxC1.Text)
	local creditCardValue = player.leaderstats:WaitForChild("Moneys").Value

	if amountToWithdraw and creditCardValue then
		if amountToWithdraw > 0 and amountToWithdraw <= creditCardValue then
			-- Subtract the amount from the credit card value
			player.leaderstats:WaitForChild("Moneys").Value = creditCardValue - amountToWithdraw
			-- Add the withdrawn amount to the player's Moneys value
			player.CreditCardValue.CreditCard1.Value = amountToWithdraw + player.CreditCardValue.CreditCard1.Value
		else
			-- Handle the case where the withdrawal amount is invalid
			print("Invalid withdrawal amount")
		end
	else
		-- Handle the case where the input is not a valid number or creditCardValue is nil
		print("Invalid input or credit card value is nil")
	end


end)

This in Starter Gui ↓ (LocalScript)

local plr = game.Players.LocalPlayer

local remote = game.ReplicatedStorage.WithDraw1
local remote2 = game.ReplicatedStorage.Deponsit1

local TextBoxC1 = script.Parent.putamont1
local Depo = script.Parent.DEPOSIT1
local With = script.Parent.WITHDRAW1

With.MouseButton1Click:Connect(function()
	
	remote:FireServer()
	
end)


Depo.MouseButton1Click:Connect(function()
	
	remote2:FireServer()
	
	
end)

สกรีนช็อต 2024-02-18 213514

Invalid input or credit card value is nil  -  Server 

↑ error , someone help me im stuck this to long
(I can’t call myself programmer anymore)

1 Like

This might be the issue.
FindFirstChild() should only be used when you are unsure whether something exists. Since this is necessary, you should use WaitForChild(). If the value is being created on the client, change it so it is created on the server.

Everyone gets stuck on something in programming - it just sometimes takes a bit of help spotting it. You get so caught up in the error that you don’t notice one bit that is off.

1 Like

UI elements aren’t in player, they’re in player.PlayerGui.

1 Like

That’s already the case in the script, from the line:
local plr = player:WaitForChild("PlayerGui")