Roblox-Bot-Lua/Main/GaG/SimpleUI_Fix.lua
2025-07-21 10:41:54 +07:00

693 lines
24 KiB
Lua

-- Simple GaG UI - Fixed Version
-- UI ที่ทำงานได้แน่นอน
print("Starting Simple GaG UI...")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local Player = Players.LocalPlayer
-- รอให้ Player พร้อม
if not Player then
repeat wait() until Players.LocalPlayer
Player = Players.LocalPlayer
end
local PlayerGui = Player:WaitForChild("PlayerGui")
print("Services loaded successfully")
-- ตรวจสอบเกม (ปิดการตรวจสอบชั่วคราว)
print("Current PlaceId:", game.PlaceId)
-- Comment out PlaceId check for testing
--[[
if game.PlaceId ~= 4442272183 then
warn("This script only works in Grow a Garden!")
return
end
--]]
-- ป้องกันการรันซ้ำ
if _G.SimpleGaGUILoaded then
print("UI already loaded, destroying old one...")
if _G.SimpleGaGUI then
_G.SimpleGaGUI:Destroy()
end
end
_G.SimpleGaGUILoaded = true
-- Settings
local Settings = {
AutoFarm = false,
AutoSell = false,
SelectedPlant = "Carrot",
FarmDelay = 1,
SellDelay = 5,
DebugMode = true
}
print("Settings initialized")
-- Debug Function
local function DebugPrint(text)
if Settings.DebugMode then
print("[DEBUG] " .. tostring(text))
end
end
-- Notification
local function Notify(title, text)
pcall(function()
game:GetService("StarterGui"):SetCore("SendNotification", {
Title = title or "GaG UI",
Text = text or "",
Duration = 3
})
end)
end
-- สร้าง UI แบบง่าย
local function CreateSimpleUI()
print("Creating UI...")
-- ลบ UI เก่า
local oldGUI = PlayerGui:FindFirstChild("SimpleGaGGUI")
if oldGUI then
oldGUI:Destroy()
end
-- ScreenGui
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "SimpleGaGGUI"
ScreenGui.Parent = PlayerGui
ScreenGui.ResetOnSpawn = false
ScreenGui.IgnoreGuiInset = true
_G.SimpleGaGUI = ScreenGui
print("ScreenGui created")
-- Main Frame
local MainFrame = Instance.new("Frame")
MainFrame.Name = "MainFrame"
MainFrame.Parent = ScreenGui
MainFrame.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
MainFrame.BorderColor3 = Color3.fromRGB(0, 162, 255)
MainFrame.BorderSizePixel = 2
MainFrame.Position = UDim2.new(0, 50, 0, 50)
MainFrame.Size = UDim2.new(0, 300, 0, 400)
MainFrame.Active = true
MainFrame.Draggable = true
print("MainFrame created")
-- Title Bar
local TitleBar = Instance.new("Frame")
TitleBar.Name = "TitleBar"
TitleBar.Parent = MainFrame
TitleBar.BackgroundColor3 = Color3.fromRGB(0, 162, 255)
TitleBar.BorderSizePixel = 0
TitleBar.Size = UDim2.new(1, 0, 0, 30)
local Title = Instance.new("TextLabel")
Title.Name = "Title"
Title.Parent = TitleBar
Title.BackgroundTransparency = 1
Title.Position = UDim2.new(0, 5, 0, 0)
Title.Size = UDim2.new(1, -35, 1, 0)
Title.Font = Enum.Font.SourceSansBold
Title.Text = "Simple GaG Auto Farm"
Title.TextColor3 = Color3.fromRGB(255, 255, 255)
Title.TextSize = 14
Title.TextXAlignment = Enum.TextXAlignment.Left
-- Close Button
local CloseButton = Instance.new("TextButton")
CloseButton.Name = "CloseButton"
CloseButton.Parent = TitleBar
CloseButton.BackgroundColor3 = Color3.fromRGB(255, 60, 60)
CloseButton.BorderSizePixel = 0
CloseButton.Position = UDim2.new(1, -30, 0, 0)
CloseButton.Size = UDim2.new(0, 30, 0, 30)
CloseButton.Font = Enum.Font.SourceSansBold
CloseButton.Text = "X"
CloseButton.TextColor3 = Color3.fromRGB(255, 255, 255)
CloseButton.TextSize = 16
print("Title and close button created")
-- Content Frame
local ContentFrame = Instance.new("Frame")
ContentFrame.Name = "ContentFrame"
ContentFrame.Parent = MainFrame
ContentFrame.BackgroundTransparency = 1
ContentFrame.Position = UDim2.new(0, 10, 0, 40)
ContentFrame.Size = UDim2.new(1, -20, 1, -50)
-- Auto Farm Section
local FarmFrame = Instance.new("Frame")
FarmFrame.Name = "FarmFrame"
FarmFrame.Parent = ContentFrame
FarmFrame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
FarmFrame.BorderColor3 = Color3.fromRGB(80, 80, 80)
FarmFrame.BorderSizePixel = 1
FarmFrame.Position = UDim2.new(0, 0, 0, 0)
FarmFrame.Size = UDim2.new(1, 0, 0, 50)
local FarmLabel = Instance.new("TextLabel")
FarmLabel.Parent = FarmFrame
FarmLabel.BackgroundTransparency = 1
FarmLabel.Position = UDim2.new(0, 10, 0, 0)
FarmLabel.Size = UDim2.new(0.6, 0, 1, 0)
FarmLabel.Font = Enum.Font.SourceSans
FarmLabel.Text = "Auto Farm"
FarmLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
FarmLabel.TextSize = 16
FarmLabel.TextXAlignment = Enum.TextXAlignment.Left
local FarmToggle = Instance.new("TextButton")
FarmToggle.Name = "FarmToggle"
FarmToggle.Parent = FarmFrame
FarmToggle.BackgroundColor3 = Color3.fromRGB(255, 80, 80)
FarmToggle.BorderSizePixel = 0
FarmToggle.Position = UDim2.new(0.6, 10, 0, 10)
FarmToggle.Size = UDim2.new(0.4, -20, 0, 30)
FarmToggle.Font = Enum.Font.SourceSansBold
FarmToggle.Text = "OFF"
FarmToggle.TextColor3 = Color3.fromRGB(255, 255, 255)
FarmToggle.TextSize = 14
print("Farm section created")
-- Plant Selection
local PlantFrame = Instance.new("Frame")
PlantFrame.Name = "PlantFrame"
PlantFrame.Parent = ContentFrame
PlantFrame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
PlantFrame.BorderColor3 = Color3.fromRGB(80, 80, 80)
PlantFrame.BorderSizePixel = 1
PlantFrame.Position = UDim2.new(0, 0, 0, 60)
PlantFrame.Size = UDim2.new(1, 0, 0, 80)
local PlantLabel = Instance.new("TextLabel")
PlantLabel.Parent = PlantFrame
PlantLabel.BackgroundTransparency = 1
PlantLabel.Position = UDim2.new(0, 10, 0, 5)
PlantLabel.Size = UDim2.new(1, -20, 0, 20)
PlantLabel.Font = Enum.Font.SourceSans
PlantLabel.Text = "Selected Plant: " .. Settings.SelectedPlant
PlantLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
PlantLabel.TextSize = 12
PlantLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Plant Buttons
local plants = {"Carrot", "Strawberry", "Tomato", "Corn", "Apple"}
for i, plant in ipairs(plants) do
local PlantButton = Instance.new("TextButton")
PlantButton.Parent = PlantFrame
PlantButton.BackgroundColor3 = Color3.fromRGB(80, 120, 80)
PlantButton.BorderSizePixel = 0
PlantButton.Position = UDim2.new(0, 10 + (i-1) * 55, 0, 30)
PlantButton.Size = UDim2.new(0, 50, 0, 40)
PlantButton.Font = Enum.Font.SourceSans
PlantButton.Text = plant
PlantButton.TextColor3 = Color3.fromRGB(255, 255, 255)
PlantButton.TextSize = 9
PlantButton.TextWrapped = true
PlantButton.MouseButton1Click:Connect(function()
Settings.SelectedPlant = plant
PlantLabel.Text = "Selected Plant: " .. plant
DebugPrint("Selected plant: " .. plant)
-- Update button colors
for _, btn in pairs(PlantFrame:GetChildren()) do
if btn:IsA("TextButton") and btn ~= PlantButton then
btn.BackgroundColor3 = Color3.fromRGB(80, 120, 80)
end
end
PlantButton.BackgroundColor3 = Color3.fromRGB(120, 180, 120)
end)
end
print("Plant selection created")
-- Auto Sell Section
local SellFrame = Instance.new("Frame")
SellFrame.Name = "SellFrame"
SellFrame.Parent = ContentFrame
SellFrame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
SellFrame.BorderColor3 = Color3.fromRGB(80, 80, 80)
SellFrame.BorderSizePixel = 1
SellFrame.Position = UDim2.new(0, 0, 0, 150)
SellFrame.Size = UDim2.new(1, 0, 0, 50)
local SellLabel = Instance.new("TextLabel")
SellLabel.Parent = SellFrame
SellLabel.BackgroundTransparency = 1
SellLabel.Position = UDim2.new(0, 10, 0, 0)
SellLabel.Size = UDim2.new(0.6, 0, 1, 0)
SellLabel.Font = Enum.Font.SourceSans
SellLabel.Text = "Auto Sell"
SellLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
SellLabel.TextSize = 16
SellLabel.TextXAlignment = Enum.TextXAlignment.Left
local SellToggle = Instance.new("TextButton")
SellToggle.Name = "SellToggle"
SellToggle.Parent = SellFrame
SellToggle.BackgroundColor3 = Color3.fromRGB(255, 80, 80)
SellToggle.BorderSizePixel = 0
SellToggle.Position = UDim2.new(0.6, 10, 0, 10)
SellToggle.Size = UDim2.new(0.4, -20, 0, 30)
SellToggle.Font = Enum.Font.SourceSansBold
SellToggle.Text = "OFF"
SellToggle.TextColor3 = Color3.fromRGB(255, 255, 255)
SellToggle.TextSize = 14
print("Sell section created")
-- Status Display
local StatusFrame = Instance.new("Frame")
StatusFrame.Name = "StatusFrame"
StatusFrame.Parent = ContentFrame
StatusFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
StatusFrame.BorderColor3 = Color3.fromRGB(80, 80, 80)
StatusFrame.BorderSizePixel = 1
StatusFrame.Position = UDim2.new(0, 0, 0, 210)
StatusFrame.Size = UDim2.new(1, 0, 1, -220)
local StatusLabel = Instance.new("TextLabel")
StatusLabel.Name = "StatusLabel"
StatusLabel.Parent = StatusFrame
StatusLabel.BackgroundTransparency = 1
StatusLabel.Position = UDim2.new(0, 10, 0, 10)
StatusLabel.Size = UDim2.new(1, -20, 1, -20)
StatusLabel.Font = Enum.Font.SourceSans
StatusLabel.Text = "Status: UI Loaded\nReady to start farming!"
StatusLabel.TextColor3 = Color3.fromRGB(200, 255, 200)
StatusLabel.TextSize = 12
StatusLabel.TextYAlignment = Enum.TextYAlignment.Top
StatusLabel.TextXAlignment = Enum.TextXAlignment.Left
StatusLabel.TextWrapped = true
print("Status display created")
-- Event Handlers
local FarmConnection
local SellConnection
-- Close Button Event
CloseButton.MouseButton1Click:Connect(function()
print("Closing UI...")
if FarmConnection then FarmConnection:Disconnect() end
if SellConnection then SellConnection:Disconnect() end
ScreenGui:Destroy()
_G.SimpleGaGUILoaded = false
_G.SimpleGaGUI = nil
end)
-- Farm functions
local function GetPlayerPlots()
local plots = {}
-- Method 1: Find Plots folder
local plotsFolder = Workspace:FindFirstChild("Plots")
if plotsFolder then
for _, plot in pairs(plotsFolder:GetChildren()) do
if plot:FindFirstChild("Owner") and plot.Owner.Value == Player then
table.insert(plots, plot)
DebugPrint("Found player plot: " .. plot.Name)
end
end
end
-- Method 2: Search all workspace
if #plots == 0 then
for _, obj in pairs(Workspace:GetChildren()) do
if obj.Name:lower():find("plot") and obj:FindFirstChild("Owner") then
if obj.Owner.Value == Player then
table.insert(plots, obj)
DebugPrint("Found player plot: " .. obj.Name)
end
end
end
end
-- Method 3: Search deeper
if #plots == 0 then
for _, obj in pairs(Workspace:GetDescendants()) do
if obj.Name:lower():find("plot") and obj:FindFirstChild("Owner") then
if obj.Owner.Value == Player then
table.insert(plots, obj)
DebugPrint("Found player plot (deep): " .. obj.Name)
end
end
end
end
DebugPrint("Total plots found: " .. #plots)
return plots
end
local function IsPlantGrown(plant)
if not plant then return false end
-- Check various growth indicators
if plant:FindFirstChild("Grown") and plant.Grown.Value then
return true
end
if plant:FindFirstChild("IsGrown") and plant.IsGrown.Value then
return true
end
if plant:FindFirstChild("Ready") and plant.Ready.Value then
return true
end
if plant:GetAttribute("Grown") then
return plant:GetAttribute("Grown")
end
if plant:GetAttribute("IsGrown") then
return plant:GetAttribute("IsGrown")
end
return false
end
local function HarvestPlant(plot)
local success = false
local plant = plot:FindFirstChild("Plant")
if not plant then return false end
-- Method 1: Try RemoteEvents
for _, obj in pairs(ReplicatedStorage:GetDescendants()) do
if obj:IsA("RemoteEvent") then
local name = obj.Name:lower()
if name:find("harvest") or name:find("collect") or name:find("pick") then
local worked = pcall(function()
obj:FireServer(plot)
end)
if worked then
DebugPrint("Harvested with: " .. obj.Name)
success = true
break
end
worked = pcall(function()
obj:FireServer(plant)
end)
if worked then
DebugPrint("Harvested with: " .. obj.Name)
success = true
break
end
end
end
end
-- Method 2: ClickDetector
if not success and plant:FindFirstChild("ClickDetector") then
pcall(function()
fireclickdetector(plant.ClickDetector)
DebugPrint("Harvested with ClickDetector")
success = true
end)
end
-- Method 3: ProximityPrompt
if not success then
local prompt = plant:FindFirstChildOfClass("ProximityPrompt")
if prompt then
pcall(function()
fireproximityprompt(prompt)
DebugPrint("Harvested with ProximityPrompt")
success = true
end)
end
end
return success
end
local function PlantSeed(plot, seedName)
local success = false
-- Method 1: Try RemoteEvents
for _, obj in pairs(ReplicatedStorage:GetDescendants()) do
if obj:IsA("RemoteEvent") then
local name = obj.Name:lower()
if name:find("plant") or name:find("buy") or name:find("seed") or name:find("purchase") then
-- Try different argument combinations
local worked = pcall(function()
obj:FireServer(seedName, plot)
end)
if worked then
DebugPrint("Planted " .. seedName .. " with: " .. obj.Name)
success = true
break
end
worked = pcall(function()
obj:FireServer(plot, seedName)
end)
if worked then
DebugPrint("Planted " .. seedName .. " with: " .. obj.Name)
success = true
break
end
worked = pcall(function()
obj:FireServer("PlantSeed", seedName, plot)
end)
if worked then
DebugPrint("Planted " .. seedName .. " with: " .. obj.Name)
success = true
break
end
end
end
end
-- Method 2: ClickDetector on plot
if not success and plot:FindFirstChild("ClickDetector") then
pcall(function()
fireclickdetector(plot.ClickDetector)
DebugPrint("Planted with ClickDetector")
success = true
end)
end
return success
end
-- Farm Toggle Event
FarmToggle.MouseButton1Click:Connect(function()
Settings.AutoFarm = not Settings.AutoFarm
if Settings.AutoFarm then
FarmToggle.BackgroundColor3 = Color3.fromRGB(80, 255, 80)
FarmToggle.Text = "ON"
DebugPrint("Auto Farm started")
Notify("Auto Farm", "Started farming!")
-- Start farming loop
FarmConnection = RunService.Heartbeat:Connect(function()
if not Settings.AutoFarm then return end
pcall(function()
local plots = GetPlayerPlots()
if #plots == 0 then
DebugPrint("No plots found!")
return
end
for i, plot in pairs(plots) do
local plant = plot:FindFirstChild("Plant")
if plant then
if IsPlantGrown(plant) then
DebugPrint("Harvesting plot " .. i)
HarvestPlant(plot)
wait(0.5)
else
DebugPrint("Plant not grown in plot " .. i)
end
else
DebugPrint("Planting " .. Settings.SelectedPlant .. " in plot " .. i)
PlantSeed(plot, Settings.SelectedPlant)
wait(0.5)
end
end
end)
wait(Settings.FarmDelay)
end)
else
FarmToggle.BackgroundColor3 = Color3.fromRGB(255, 80, 80)
FarmToggle.Text = "OFF"
DebugPrint("Auto Farm stopped")
Notify("Auto Farm", "Stopped farming!")
if FarmConnection then
FarmConnection:Disconnect()
FarmConnection = nil
end
end
StatusLabel.Text = string.format("Auto Farm: %s\nSelected Plant: %s",
Settings.AutoFarm and "ON" or "OFF",
Settings.SelectedPlant)
end)
-- Sell function
local function SellItems()
local success = false
-- Method 1: Try RemoteEvents
for _, obj in pairs(ReplicatedStorage:GetDescendants()) do
if obj:IsA("RemoteEvent") then
local name = obj.Name:lower()
if name:find("sell") or name:find("shop") or name:find("trade") then
local worked = pcall(function()
obj:FireServer()
end)
if worked then
DebugPrint("Sold with: " .. obj.Name)
success = true
break
end
worked = pcall(function()
obj:FireServer("SellAll")
end)
if worked then
DebugPrint("Sold all with: " .. obj.Name)
success = true
break
end
end
end
end
-- Method 2: Find sell areas and click
if not success then
for _, obj in pairs(Workspace:GetDescendants()) do
local name = obj.Name:lower()
if name:find("sell") or name:find("shop") or name:find("store") then
-- Try ClickDetector
local clickDetector = obj:FindFirstChildOfClass("ClickDetector")
if clickDetector then
pcall(function()
fireclickdetector(clickDetector)
DebugPrint("Sold with ClickDetector: " .. obj.Name)
success = true
end)
if success then break end
end
-- Try ProximityPrompt
local prompt = obj:FindFirstChildOfClass("ProximityPrompt")
if prompt then
pcall(function()
fireproximityprompt(prompt)
DebugPrint("Sold with ProximityPrompt: " .. obj.Name)
success = true
end)
if success then break end
end
end
end
end
return success
end
-- Sell Toggle Event
SellToggle.MouseButton1Click:Connect(function()
Settings.AutoSell = not Settings.AutoSell
if Settings.AutoSell then
SellToggle.BackgroundColor3 = Color3.fromRGB(80, 255, 80)
SellToggle.Text = "ON"
DebugPrint("Auto Sell started")
Notify("Auto Sell", "Started selling!")
-- Start selling loop
SellConnection = RunService.Heartbeat:Connect(function()
if not Settings.AutoSell then return end
pcall(function()
if SellItems() then
DebugPrint("Selling successful")
else
DebugPrint("No sell method found")
end
end)
wait(Settings.SellDelay)
end)
else
SellToggle.BackgroundColor3 = Color3.fromRGB(255, 80, 80)
SellToggle.Text = "OFF"
DebugPrint("Auto Sell stopped")
Notify("Auto Sell", "Stopped selling!")
if SellConnection then
SellConnection:Disconnect()
SellConnection = nil
end
end
end)
print("Event handlers connected")
-- Update status every few seconds
spawn(function()
while ScreenGui.Parent do
StatusLabel.Text = string.format(
"Status: Running\nFarm: %s | Sell: %s\nPlant: %s\nPlaceId: %d",
Settings.AutoFarm and "ON" or "OFF",
Settings.AutoSell and "ON" or "OFF",
Settings.SelectedPlant,
game.PlaceId
)
wait(3)
end
end)
print("UI created successfully!")
Notify("GaG UI", "UI loaded successfully! 🌱")
return ScreenGui
end
-- Initialize
print("Initializing Simple GaG UI...")
-- Create UI with error handling
local success, result = pcall(CreateSimpleUI)
if success then
print("✅ Simple GaG UI loaded successfully!")
DebugPrint("UI is ready to use")
else
warn("❌ Failed to create UI: " .. tostring(result))
print("Error details:", result)
end
-- Global functions for manual control
_G.GaGUI = {
Settings = Settings,
DebugPrint = DebugPrint
}
print("Script execution completed")