FocusLost is not a valid member of ScreenGui

What I would l to achieve is when a player enters a number in the textbox, the amount will be deducted from their account, and then spawn the amount of boxes they purchased outside the store

Summary

I haven’t figured out how to spawn the boxes outside the store. I’m trying to get the buying side working before moving on. If you have any tips on getting the boxes to spawn outside, please let me know.

Directory

My issue is when I last worked on this, I didn’t have any issues, and now it’s giving me an error: FocusLost is not a valid member of ScrollingFrame “Players.ryan97rut.PlayerGui.ShopGui.ShopMainFrame” - Client - shopScript:26

Shop Script:

Summary
local frame = script.Parent
local TextBox = script.Parent
local open = workspace.openPart
local close = workspace.closePart
local closeBtn = frame.CloseButton
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local Gold = localPlayer.leaderstats.Gold
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.buySeeds
local errorGui = game.StarterGui.ErrorGui

frame.Visible = false

local price = {
	['Wheat'] = 100, 
	['Corn'] = 250, 
	['Rice'] = 2000, 
	['Bamboo'] = 8400, 
	['Soybean'] = 24000, 
	['Cabbage'] = 57600, 
	['Carrot'] = 85000, 
	['Potato'] = 120000
}

TextBox.FocusLost:Connect(function(ItemName, player)
	for _,UI in pairs(script.Parent:GetDescendants()) do
		if UI:IsA('TextButton') then
			UI.MouseButton1Click:Connect(function(ItemName, player)
				local AmountPurchase = tonumber(UI.Parent:FindFirstChild('TextBox').Name)
				local Seed = UI.Parent:FindFirstChildOfClass('TextBox').Name:gsub('BuyAmount','')

				if AmountPurchase then
					for i=1,AmountPurchase do
						print(Gold.Value, price[Seed])
						if Gold.Value >= price[Seed] then
							Gold.Value -= price[Seed]
							print("Successfully Purchased")
						elseif Gold.Value < price[Seed] then
							print("Insufficient Funds")
							errorGui.Enabled = true
						end
					end
				end
			end)
		end
	end
end)
	
	local function openMenu(otherPart)
		local player = Players:GetPlayerFromCharacter(otherPart.Parent)
		if player.Name == localPlayer.Name then
			frame.Visible = true
			localPlayer.Character.Humanoid.WalkSpeed = 0
		end
	end

	local function closeMenu()
		frame.Visible = false
		localPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(
			close.Position.X, close.Position.Y + 3, close.Position.Z)
		localPlayer.Character.Humanoid.WalkSpeed = 16
	end

	open.Touched:Connect(openMenu)
	closeBtn.MouseButton1Click:Connect(closeMenu)

Did you forget to reference the TextBox variable as

local TextBox = script.Parent.CloseButton

?

Tried that, and it throws the same error, but with not a member of a textbutton

1 Like

How though?

image

Do you have another object that’s named as “CloseButton” that could be intercepting the script?

I also just realized you’re getting the StarterGui instead of the Player’s Gui

local frame = script.Parent
local TextBox = frame:WaitForChild("CloseButton")

print(TextBox)

local open = workspace.openPart
local close = workspace.closePart
local closeBtn = frame.CloseButton
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local Gold = localPlayer.leaderstats.Gold
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage.buySeeds
local errorGui = localPlayer.PlayerGui:WaitForChild("ErrorGui")

frame.Visible = false

local price = {
	['Wheat'] = 100, 
	['Corn'] = 250, 
	['Rice'] = 2000, 
	['Bamboo'] = 8400, 
	['Soybean'] = 24000, 
	['Cabbage'] = 57600, 
	['Carrot'] = 85000, 
	['Potato'] = 120000
}

TextBox.FocusLost:Connect(function(ItemName, player)
	for _,UI in pairs(script.Parent:GetDescendants()) do
		if UI:IsA('TextButton') then
			UI.MouseButton1Click:Connect(function(ItemName, player)
				local AmountPurchase = tonumber(UI.Parent:FindFirstChild('TextBox').Name)
				local Seed = UI.Parent:FindFirstChildOfClass('TextBox').Name:gsub('BuyAmount','')

				if AmountPurchase then
					for i=1,AmountPurchase do
						print(Gold.Value, price[Seed])
						if Gold.Value >= price[Seed] then
							Gold.Value -= price[Seed]
							print("Successfully Purchased")
						elseif Gold.Value < price[Seed] then
							print("Insufficient Funds")
							errorGui.Enabled = true
						end
					end
				end
			end)
		end
	end
end)
	
	local function openMenu(otherPart)
		local player = Players:GetPlayerFromCharacter(otherPart.Parent)
		if player.Name == localPlayer.Name then
			frame.Visible = true
			localPlayer.Character.Humanoid.WalkSpeed = 0
		end
	end

	local function closeMenu()
		frame.Visible = false
		localPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(
			close.Position.X, close.Position.Y + 3, close.Position.Z)
		localPlayer.Character.Humanoid.WalkSpeed = 16
	end

	open.Touched:Connect(openMenu)
	closeBtn.MouseButton1Click:Connect(closeMenu)

FocusLost is not a valid member of TextButton “Players.ryan97rut.PlayerGui.ShopGui.ShopMainFrame.CloseButton” - Client - shopScript:28

No other part is named CloseButton

Prints out CloseButton
What the Gui looks like ingame
Ignore the red tint as its just the overlay for if the player doesn’t have enough money to purchase

Well you’re not showing another TextBox object in the image you sent, you’ll have to create 1 if you want to be able to use the TextBox.FocusLost event & detect its connections

Here is where the textbox is located. There are 7 other folders that have the same layout