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.
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)