Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to fix FocusLost isnt a valid member of ScreenGui?

FocusLost is not a valid member of ScreenGui "Players.ryan97rut.PlayerGui.ShopGui" is the error

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)

1 comment

0

What instance is the script parented too?

2 answers

I think your doing focus lost of a screen gui and not a real gui object.

Focus lost is a property of TextBox and not ScreenGui.

This discussion is preserved as it was. New answers, comments, and votes are closed.