-- SERVICES
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
-- REMOTES
local ChestDeleteRemote = ReplicatedStorage.Remotes:WaitForChild("ChestDelete")
-- STATE
local State = {
AutoDeleteChests = false,
DeleteChests = {}, -- chest toggle states
SeenChests = {} -- prevents first-time deletion
}
-- ===== GUI =====
local ScreenGui = Instance.new("ScreenGui", LocalPlayer.PlayerGui)
-- MAIN FRAME
local Frame = Instance.new("Frame")
Frame.Size = UDim2.new(0, 300, 0, 450)
Frame.Position = UDim2.new(0, 20, 0, 60)
Frame.BackgroundColor3 = Color3.fromRGB(30,30,30)
Frame.BorderSizePixel = 0
Frame.Active = true
Frame.Draggable = true
Frame.Parent = ScreenGui
-- AUTO DELETE TOGGLE
local AutoToggle = Instance.new("TextButton", Frame)
AutoToggle.Size = UDim2.new(1,-10,0,40)
AutoToggle.Position = UDim2.new(0,5,0,10)
AutoToggle.TextColor3 = Color3.new(1,1,1)
AutoToggle.BackgroundColor3 = Color3.fromRGB(60,60,60)
AutoToggle.Text = "Auto Delete: OFF"
AutoToggle.MouseButton1Click:Connect(function()
State.AutoDeleteChests = not State.AutoDeleteChests
AutoToggle.Text = "Auto Delete: " .. (State.AutoDeleteChests and "ON" or "OFF")
end)
-- REFRESH BUTTON
local Refresh = Instance.new("TextButton", Frame)
Refresh.Size = UDim2.new(1,-10,0,40)
Refresh.Position = UDim2.new(0,5,0,55)
Refresh.TextColor3 = Color3.new(1,1,1)
Refresh.BackgroundColor3 = Color3.fromRGB(80,80,80)
Refresh.Text = "Refresh Chests"
-- SCROLL
local Scroll = Instance.new("ScrollingFrame", Frame)
Scroll.Position = UDim2.new(0,5,0,105)
Scroll.Size = UDim2.new(1,-10,1,-115)
Scroll.CanvasSize = UDim2.new(0,0,0,0)
Scroll.ScrollBarThickness = 8
Scroll.BackgroundTransparency = 1
local Layout = Instance.new("UIListLayout", Scroll)
Layout.Padding = UDim.new(0,5)
Layout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
Scroll.CanvasSize = UDim2.new(0,0,0,Layout.AbsoluteContentSize.Y + 5)
end)
-- CREATE TOGGLE
local function createChestToggle(chestName)
if State.DeleteChests[chestName] ~= nil then return end
State.DeleteChests[chestName] = false
local btn = Instance.new("TextButton", Scroll)
btn.Size = UDim2.new(1,-10,0,35)
btn.Text = chestName
btn.TextColor3 = Color3.new(1,1,1)
btn.BackgroundColor3 = Color3.fromRGB(150,0,0)
btn.MouseButton1Click:Connect(function()
State.DeleteChests[chestName] = not State.DeleteChests[chestName]
btn.BackgroundColor3 = State.DeleteChests[chestName]
and Color3.fromRGB(0,150,0)
or Color3.fromRGB(150,0,0)
end)
end
-- SCAN CHESTS
local function scanChests()
local slots = LocalPlayer:FindFirstChild("ChestSlots")
if not slots then return end
for _,slot in ipairs(slots:GetChildren()) do
local nameVal = slot:FindFirstChild("ChestName")
if nameVal and nameVal.Value ~= "" then
createChestToggle(nameVal.Value)
end
end
end
Refresh.MouseButton1Click:Connect(scanChests)
-- WATCH FOR NEW CHESTS
local function watchSlots()
local slots = LocalPlayer:WaitForChild("ChestSlots")
for _,slot in ipairs(slots:GetChildren()) do
local nameVal = slot:WaitForChild("ChestName")
nameVal:GetPropertyChangedSignal("Value"):Connect(scanChests)
end
end
watchSlots()
scanChests()
-- AUTO DELETE LOOP (FIXED)
task.spawn(function()
while true do
if State.AutoDeleteChests then
local slots = LocalPlayer:FindFirstChild("ChestSlots")
if slots then
for i,slot in ipairs(slots:GetChildren()) do
local nameVal = slot:FindFirstChild("ChestName")
local stateVal = slot:FindFirstChild("State")
if nameVal and stateVal and stateVal.Value == "Locked" then
local chest = nameVal.Value
-- FIRST TIME SAFETY
if not State.SeenChests[chest] then
State.SeenChests[chest] = true
elseif State.DeleteChests[chest] then
pcall(function()
ChestDeleteRemote:FireServer(i)
end)
end
end
end
end
end
task.wait(0.05)
end
end)
-- GUI TOGGLE BUTTON
local Mini = Instance.new("TextButton", ScreenGui)
Mini.Size = UDim2.new(0,100,0,30)
Mini.Position = UDim2.new(0,10,0,10)
Mini.Text = "Toggle GUI"
Mini.TextColor3 = Color3.new(1,1,1)
Mini.BackgroundColor3 = Color3.fromRGB(80,80,80)
Mini.Active = true
Mini.Draggable = true
Mini.MouseButton1Click:Connect(function()
Frame.Visible = not Frame.Visible
end)
Comments
thanks its working, but there is problem the chest will be deleted when you first get it using the script, then it will not be deleted if you do not press the auto delete button on the chests, I got a christmas25 chest but it was deleted but when I got it the second time it was not deleted, can you please fix the problem