Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to fix FocusLost isnt a valid member of ScreenGui?

Asked by 3 years ago

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)
0
What instance is the script parented too? Hypoxla 125 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Focus lost is a property of TextBox and not ScreenGui.

Answer this question