всё засунь внутрь toggle
засунь всё в toggle только самое важное оставь снаружи по типо переменных ну короче давай
repeat task.wait() until game:IsLoaded()
local MainTab = Window:CreateTab("Main", "activity")
getgenv().AutoAll = false
local autoAllTask, flipLoopTask, autoReplayTask, sosaltask
local SAFE_PLACE = Vector3.new(0,300,0)
local RETURN_POSITION = Vector3.new(-2866.146, 135.067902, 4350.21533)
-- Настройки для небольших задержек.
local PRESS_BS_DURATION = 0.07 -- Задержка для BackSlash
local PRESS_RETURN_DURATION = 0.05
local TELEPORT_DELAY = 0.2
local FLIP_SPAM = 5
local FLIP_LOOP_WAIT = 0.1
local function teleportTo(pos)
local plr = game:GetService("Players").LocalPlayer
if not plr then return end
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart", 5)
if hrp then
hrp.CFrame = CFrame.new(pos)
task.wait(TELEPORT_DELAY)
end
end
-- Эта функция ищет подходящую BasePart (PrimaryPart, HumanoidRootPart и т.д.)
local function findBasePart(x)
if x:IsA("Model") then
if x.PrimaryPart then
return x.PrimaryPart
end
local a = x:FindFirstChild("HumanoidRootPart")
if a and a:IsA("BasePart") then
return a
end
local b = x:FindFirstChildWhichIsA("BasePart")
if b then
return b
end
elseif x:IsA("BasePart") then
return x
end
return nil
end
-- Вместо нажатия E используем fireproximityprompt
local function firePrompt(obj)
if not obj then return end
local prompt = obj:FindFirstChildOfClass("ProximityPrompt")
if prompt then
-- Вызов FireProximityPrompt. Вторым аргументом можно указать время удержания (по умолчанию 1).
-- Третий аргумент (true/false) – имитация нажатия кнопки "Hold" или нет.
fireproximityprompt(prompt, 1)
end
end
-- Спавм флип-лук для лута (анимация Flip)
local function spamFlipLoop()
local plr = game:GetService("Players").LocalPlayer
local lootGui = plr and plr:WaitForChild("PlayerGui"):WaitForChild("Loot", 10)
if not lootGui or not lootGui:IsA("ScreenGui") then return end
while getgenv().AutoAll do
if lootGui.Enabled then
-- "Открываем" GUI через BackSlash (имитация)
game:GetService("VirtualInputManager"):SendKeyEvent(true, Enum.KeyCode.BackSlash, false, game)
task.wait(0.05)
local frame = lootGui:FindFirstChild("Frame")
if frame then
local flip = frame:FindFirstChild("Flip")
if flip and flip:IsA("GuiObject") then
game:GetService("GuiService").SelectedObject = flip
task.wait(0.05)
for i = 1, FLIP_SPAM do
game:GetService("VirtualInputManager"):SendKeyEvent(true, Enum.KeyCode.Return, false, game)
task.wait(PRESS_RETURN_DURATION)
game:GetService("VirtualInputManager"):SendKeyEvent(false, Enum.KeyCode.Return, false, game)
task.wait(0.02)
end
end
end
-- "Закрываем" GUI
game:GetService("VirtualInputManager"):SendKeyEvent(false, Enum.KeyCode.BackSlash, false, game)
task.wait(0.1)
else
task.wait(FLIP_LOOP_WAIT)
end
end
end
Assistant
-- Когда появляется Finger Bearer, телепортируемся на платформу и потом к нему
local function handleFingerBearerSpawned(c)
if not getgenv().AutoAll then return end
if c.Name == "Finger Bearer" and c:IsA("Model") then
-- Телепорт на зелёную платформу
teleportTo(safePlatform.Position + Vector3.new(0, 5, 0))
task.wait(10) -- небольшая пауза
local bp = findBasePart(c)
if bp then
teleportTo(bp.Position + Vector3.new(0, 2, 0))
end
end
end
-- Следим, когда появится Finger Bearer
local function monitorFingerBearer()
local mf = workspace:FindFirstChild("Objects") and workspace.Objects:FindFirstChild("Mobs")
if not mf or not mf:IsA("Folder") then return end
for _, x in ipairs(mf:GetChildren()) do
handleFingerBearerSpawned(x)
end
mf.ChildAdded:Connect(handleFingerBearerSpawned)
end
-- Обработка цивилов (Civilian)
local function processCivilian(c)
if not getgenv().AutoAll then return end
local bp = findBasePart(c)
if bp then
teleportTo(bp.Position + Vector3.new(0,1.5,0))
firePrompt(c)
task.wait(0.2)
teleportTo(RETURN_POSITION)
task.wait(0.2)
end
end
-- Обработка проклятых объектов (CursedObject)
local function processCursedObject(o)
if not getgenv().AutoAll then return end
local bp = findBasePart(o)
if bp then
teleportTo(bp.Position + Vector3.new(0,1.5,0))
firePrompt(o)
task.wait(0.2)
teleportTo(RETURN_POSITION)
task.wait(0.2)
end
end
-- Обработка сундуков
local function processChest(ch)
if not getgenv().AutoAll then return end
local bp = findBasePart(ch)
if bp then
teleportTo(bp.Position + Vector3.new(0,1.5,0))
firePrompt(ch)
-- Делаем небольшую задержку, чтобы сундук успел открыться и не все открывались разом
task.wait(0.5)
teleportTo(RETURN_POSITION)
task.wait(0.2)
end
end
-- Обработка мобов (включая Finger Bearer — убрали return)
local function processMob(m)
if not getgenv().AutoAll then return end
if m.Name == "Finger Bearer" then
wait(10)
end
local bp = findBasePart(m)
if bp then
teleportTo(bp.Position + Vector3.new(0,2,0))
-- Если у моба есть проксимити-промпт (редко, но пусть будет)
firePrompt(m)
task.wait(0.2)
teleportTo(RETURN_POSITION)
task.wait(0.2)
end
end
-- Главный цикл "всё в одном"
local function autoAllLoop()
monitorFingerBearer()
while getgenv().AutoAll do
local obj = workspace:FindFirstChild("Objects")
if not obj then
task.wait(0.5)
continue
end
code
local mis = obj:FindFirstChild("MissionItems")
local drp = obj:FindFirstChild("Drops")
local mob = obj:FindFirstChild("Mobs")
local foundSomething = false
-- Civilian / CursedObject
if mis and mis:IsA("Folder") then
for _, i in ipairs(mis:GetChildren()) do
if not getgenv().AutoAll then break end
if i.Name=="Civilian" then
foundSomething = true
processCivilian(i)
elseif i.Name=="CursedObject" then
foundSomething = true
processCursedObject(i)
end
end
end
-- Сундуки (Drops)
if drp and drp:IsA("Folder") then
for _, d in ipairs(drp:GetDescendants()) do
if not getgenv().AutoAll then break end
-- Ищем слово "chest" в названии
if d:IsA("Model") and string.find(d.Name:lower(), "chest") then
foundSomething = true
processChest(d)
end
end
end
-- Мобы (Mobs)
if mob and mob:IsA("Folder") then
for _, mm in ipairs(mob:GetChildren()) do
if not getgenv().AutoAll then break end
if mm:IsA("Model") then
foundSomething = true
processMob(mm)
end
end
end
if not foundSomething then
task.wait(0.5)
end
end
end
getgenv().InstaKill = true
task.spawn(function()
while getgenv().InstaKill do
pcall(function()
local mobs = workspace.Objects.Mobs
if mobs and mobs:IsA("Folder") then
for _, mob in ipairs(mobs:GetChildren()) do
if mob:IsA("Model") and mob:FindFirstChildOfClass("Humanoid") then
local humanoid = mob:FindFirstChildOfClass("Humanoid")
if humanoid and humanoid.Health > 0 then
humanoid:ChangeState(15) -- Деактивирует Humanoid
humanoid.Health = 0 -- Устанавливает здоровье в 0
end
end
end
else
warn("Mobs folder not found or is not a folder.")
end
end)
task.wait(0.01) -- Быстрая обработка
end
end)
local hrp = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local bp = Instance.new("BodyPosition", hrp)
bp.MaxForce = Vector3.new(1e5, 1e5, 1e5)
bp.Position = hrp.Position
local function sosal()
while getgenv().AutoAll do
game:GetService("ReplicatedStorage").Remotes.Client.StorylineDialogueSkip:FireServer(true)
task.wait()
end
end
-- Автоповтор (Replay) без 20-секундного ожидания, ставим короткую задержку
local function autoReplayLoop()
local plr = game:GetService("Players").LocalPlayer
local pg = plr and plr:FindFirstChild("PlayerGui")
if not pg then return end
while getgenv().AutoAll do
local rs = pg:FindFirstChild("ReadyScreen")
if rs and rs:IsA("ScreenGui") and rs.Enabled then
-- Короткая задержка вместо 20 секунд
task.wait(2)
if getgenv().AutoAll and rs.Enabled then
local frm = rs:FindFirstChild("Frame")
if frm then
local rply = frm:FindFirstChild("Replay")
if rply and rply:IsA("GuiButton") then
local vim = game:GetService("VirtualInputManager")
local gs = game:GetService("GuiService")
-- Открываем GUI
vim:SendKeyEvent(true,Enum.KeyCode.BackSlash,false,game)
task.wait(0.2)
gs.SelectedObject = rply
task.wait(0.2)
-- Нажимаем Enter
vim:SendKeyEvent(true,Enum.KeyCode.Return,false,game)
task.wait(0.1)
vim:SendKeyEvent(false,Enum.KeyCode.Return,false,game)
task.wait(0.1)
-- Закрываем GUI
vim:SendKeyEvent(true,Enum.KeyCode.BackSlash,false,game)
vim:SendKeyEvent(false,Enum.KeyCode.BackSlash,false,game)
end
end
end
end
task.wait(1)
end
end
MainTab:CreateToggle({
Name = "All in one Toggle + AutoReplay",
CurrentValue = false,
Flag = "AutoAll",
Callback = function(state)
getgenv().AutoAll = state
if state then
autoAllTask = task.spawn(autoAllLoop)
flipLoopTask = task.spawn(spamFlipLoop)
autoReplayTask = task.spawn(autoReplayLoop)
sosaltask = task.spawn(sosal)
else
getgenv().AutoAll = false
autoAllTask = nil
flipLoopTask = nil
autoReplayTask = nil
end
end,
})
MainTab:CreateLabel("All logic + AutoReplay in 1 Toggle", "rewind")
Rayfield:LoadConfiguration()
Here's your script with most of the code moved inside the toggle's callback function, leaving only essential variables outside as you requested:
lua
repeat task.wait() until game:IsLoaded()
local Rayfield = loadstring(game:HttpGet('https://sirius.menu/rayfield'))()
local Window = Rayfield:CreateWindow({
Name = "Prime Hub JJI Investigate (Fixed)",
Icon = "home",
LoadingTitle = "Prime Hub",
LoadingSubtitle = "Loading...",
Theme = "Default",
DisableRayfieldPrompts = false,
DisableBuildWarnings = false,
ConfigurationSaving = {
Enabled = true,
FolderName = "Prime Hub",
FileName = "JJI Investigate"
},
Discord = {
Enabled = true,
Invite = "primeh",
RememberJoins = true
},
})
local MainTab = Window:CreateTab("Main", "activity")
getgenv().AutoAll = false
MainTab:CreateToggle({
Name = "All in one Toggle + AutoReplay",
CurrentValue = false,
Flag = "AutoAll",
Callback = function(state)
getgenv().AutoAll = state
if state then
-- All the code inside the toggle
-- Define variables necessary inside the toggle
local autoAllTask, flipLoopTask, autoReplayTask, sosaltask
local SAFE_PLACE = Vector3.new(0,300,0)
local RETURN_POSITION = Vector3.new(-2866.146, 135.067902, 4350.21533)
-- Настройки для небольших задержек.
local PRESS_BS_DURATION = 0.07 -- Задержка для BackSlash
local PRESS_RETURN_DURATION = 0.05
local TELEPORT_DELAY = 0.2
local FLIP_SPAM = 5
local FLIP_LOOP_WAIT = 0.1
-- Создаём неоновую платформу для "безопасной" точки
local safePlatform = Instance.new("Part")
safePlatform.Name = "SafePlatform"
safePlatform.Anchored = true
safePlatform.Size = Vector3.new(100, 1, 100)
safePlatform.Position = SAFE_PLACE
safePlatform.Material = Enum.Material.Neon
safePlatform.BrickColor = BrickColor.new("Bright green")
safePlatform.CanCollide = true
safePlatform.Parent = workspace
local function teleportTo(pos)
local plr = game:GetService("Players").LocalPlayer
if not plr then return end
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart", 5)
if hrp then
hrp.CFrame = CFrame.new(pos)
task.wait(TELEPORT_DELAY)
end
end
-- Эта функция ищет подходящую BasePart (PrimaryPart, HumanoidRootPart и т.д.)
local function findBasePart(x)
if x:IsA("Model") then
if x.PrimaryPart then
return x.PrimaryPart
end
local a = x:FindFirstChild("HumanoidRootPart")
if a and a:IsA("BasePart") then
return a
end
local b = x:FindFirstChildWhichIsA("BasePart")
if b then
return b
end
elseif x:IsA("BasePart") then
return x
end
return nil
end
-- Вместо нажатия E используем fireproximityprompt
local function firePrompt(obj)
if not obj then return end
local prompt = obj:FindFirstChildOfClass("ProximityPrompt")
if prompt then
-- Вызов FireProximityPrompt. Вторым аргументом можно указать время удержания (по умолчанию 1).
-- Третий аргумент (true/false) – имитация нажатия кнопки "Hold" или нет.
fireproximityprompt(prompt, 1)
end
end
-- Спавм флип-лук для лута (анимация Flip)
local function spamFlipLoop()
local plr = game:GetService("Players").LocalPlayer
local lootGui = plr and plr:WaitForChild("PlayerGui"):WaitForChild("Loot", 10)
if not lootGui or not lootGui:IsA("ScreenGui") then return end
while getgenv().AutoAll do
if lootGui.Enabled then
-- "Открываем" GUI через BackSlash (имитация)
game:GetService("VirtualInputManager"):SendKeyEvent(true, Enum.KeyCode.BackSlash, false, game)
task.wait(0.05)
local frame = lootGui:FindFirstChild("Frame")
if frame then
local flip = frame:FindFirstChild("Flip")
if flip and flip:IsA("GuiObject") then
game:GetService("GuiService").SelectedObject = flip
task.wait(0.05)
for i = 1, FLIP_SPAM do
game:GetService("VirtualInputManager"):SendKeyEvent(true, Enum.KeyCode.Return, false, game)
task.wait(PRESS_RETURN_DURATION)
game:GetService("VirtualInputManager"):SendKeyEvent(false, Enum.KeyCode.Return, false, game)
task.wait(0.02)
end
end
end
-- "Закрываем" GUI
game:GetService("VirtualInputManager"):SendKeyEvent(false, Enum.KeyCode.BackSlash, false, game)
task.wait(0.1)
else
task.wait(FLIP_LOOP_WAIT)
end
end
end
-- Когда появляется Finger Bearer, телепортируемся на платформу и потом к нему
local function handleFingerBearerSpawned(c)
if not getgenv().AutoAll then return end
if c.Name == "Finger Bearer" and c:IsA("Model") then
-- Телепорт на зелёную платформу
teleportTo(safePlatform.Position + Vector3.new(0, 5, 0))
task.wait(10) -- небольшая пауза
local bp = findBasePart(c)
if bp then
teleportTo(bp.Position + Vector3.new(0, 2, 0))
end
end
end
-- Следим, когда появится Finger Bearer
local function monitorFingerBearer()
local mf = workspace:FindFirstChild("Objects") and workspace.Objects:FindFirstChild("Mobs")
if not mf or not mf:IsA("Folder") then return end
for _, x in ipairs(mf:GetChildren()) do
handleFingerBearerSpawned(x)
end
mf.ChildAdded:Connect(handleFingerBearerSpawned)
end
-- Обработка цивилов (Civilian)
local function processCivilian(c)
if not getgenv().AutoAll then return end
local bp = findBasePart(c)
if bp then
teleportTo(bp.Position + Vector3.new(0,1.5,0))
firePrompt(c)
task.wait(0.2)
teleportTo(RETURN_POSITION)
task.wait(0.2)
end
end
-- Обработка проклятых объектов (CursedObject)
local function processCursedObject(o)
if not getgenv().AutoAll then return end
local bp = findBasePart(o)
if bp then
teleportTo(bp.Position + Vector3.new(0,1.5,0))
firePrompt(o)
task.wait(0.2)
teleportTo(RETURN_POSITION)
task.wait(0.2)
end
end
-- Обработка сундуков
local function processChest(ch)
if not getgenv().AutoAll then return end
local bp = findBasePart(ch)
if bp then
teleportTo(bp.Position + Vector3.new(0,1.5,0))
firePrompt(ch)
-- Делаем небольшую задержку, чтобы сундук успел открыться и не все открывались разом
task.wait(0.5)
teleportTo(RETURN_POSITION)
task.wait(0.2)
end
end
-- Обработка мобов (включая Finger Bearer — убрали return)
local function processMob(m)
if not getgenv().AutoAll then return end
if m.Name == "Finger Bearer" then
wait(10)
end
local bp = findBasePart(m)
if bp then
teleportTo(bp.Position + Vector3.new(0,2,0))
-- Если у моба есть проксимити-промпт (редко, но пусть будет)
firePrompt(m)
task.wait(0.2)
teleportTo(RETURN_POSITION)
task.wait(0.2)
end
end
-- Главный цикл "всё в одном"
local function autoAllLoop()
monitorFingerBearer()
while getgenv().AutoAll do
local obj = workspace:FindFirstChild("Objects")
if not obj then
task.wait(0.5)
continue
end
local mis = obj:FindFirstChild("MissionItems")
local drp = obj:FindFirstChild("Drops")
local mob = obj:FindFirstChild("Mobs")
local foundSomething = false
-- Civilian / CursedObject
if mis and mis:IsA("Folder") then
for _, i in ipairs(mis:GetChildren()) do
if not getgenv().AutoAll then break end
if i.Name=="Civilian" then
foundSomething = true
processCivilian(i)
elseif i.Name=="CursedObject" then
foundSomething = true
processCursedObject(i)
end
end
end
-- Сундуки (Drops)
if drp and drp:IsA("Folder") then
for _, d in ipairs(drp:GetDescendants()) do
if not getgenv().AutoAll then break end
-- Ищем слово "chest" в названии
if d:IsA("Model") and string.find(d.Name:lower(), "chest") then
foundSomething = true
processChest(d)
end
end
end
-- Мобы (Mobs)
if mob and mob:IsA("Folder") then
for _, mm in ipairs(mob:GetChildren()) do
if not getgenv().AutoAll then break end
if mm:IsA("Model") then
foundSomething = true
processMob(mm)
end
end
end
if not foundSomething then
task.wait(0.5)
end
end
end
getgenv().InstaKill = true
task.spawn(function()
while getgenv().InstaKill do
pcall(function()
local mobs = workspace.Objects.Mobs
if mobs and mobs:IsA("Folder") then
for _, mob in ipairs(mobs:GetChildren()) do
if mob:IsA("Model") and mob:FindFirstChildOfClass("Humanoid") then
local humanoid = mob:FindFirstChildOfClass("Humanoid")
if humanoid and humanoid.Health > 0 then
humanoid:ChangeState(15) -- Деактивирует Humanoid
humanoid.Health = 0 -- Устанавливает здоровье в 0
end
end
end
else
warn("Mobs folder not found or is not a folder.")
end
end)
task.wait(0.01) -- Быстрая обработка
end
end)
local hrp = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local bp = Instance.new("BodyPosition", hrp)
bp.MaxForce = Vector3.new(1e5, 1e5, 1e5)
bp.Position = hrp.Position
game:GetService("RunService").Stepped:Connect(function()
bp.Position = hrp.Position
end)
local function sosal()
while getgenv().AutoAll do
game:GetService("ReplicatedStorage").Remotes.Client.StorylineDialogueSkip:FireServer(true)
task.wait()
end
end
-- Автоповтор (Replay) без 20-секундного ожидания, ставим короткую задержку
local function autoReplayLoop()
local plr = game:GetService("Players").LocalPlayer
local pg = plr and plr:FindFirstChild("PlayerGui")
if not pg then return end
while getgenv().AutoAll do
local rs = pg:FindFirstChild("ReadyScreen")
if rs and rs:IsA("ScreenGui") and rs.Enabled then
-- Короткая задержка вместо 20 секунд
task.wait(2)
if getgenv().AutoAll and rs.Enabled then
local frm = rs:FindFirstChild("Frame")
if frm then
local rply = frm:FindFirstChild("Replay")
if rply and rply:IsA("GuiButton") then
local vim = game:GetService("VirtualInputManager")
local gs = game:GetService("GuiService")
-- Открываем GUI
vim:SendKeyEvent(true,Enum.KeyCode.BackSlash,false,game)
task.wait(0.2)
gs.SelectedObject = rply
task.wait(0.2)
-- Нажимаем Enter
vim:SendKeyEvent(true,Enum.KeyCode.Return,false,game)
task.wait(0.1)
vim:SendKeyEvent(false,Enum.KeyCode.Return,false,game)
task.wait(0.1)
-- Закрываем GUI
vim:SendKeyEvent(true,Enum.KeyCode.BackSlash,false,game)
vim:SendKeyEvent(false,Enum.KeyCode.BackSlash,false,game)
end
end
end
end
task.wait(1)
end
end
getgenv().InstaKill = true
autoAllTask = task.spawn(autoAllLoop)
flipLoopTask = task.spawn(spamFlipLoop)
autoReplayTask = task.spawn(autoReplayLoop)
sosaltask = task.spawn(sosal)
else
getgenv().AutoAll = false
getgenv().InstaKill = false
-- You can add any cleanup code here if needed.
end
end,
})
MainTab:CreateLabel("All logic + AutoReplay in 1 Toggle", "rewind")
Rayfield:LoadConfiguration()
Explanation:
Variables Outside the Toggle: Only the essential variables like getgenv().AutoAll, the Rayfield UI setup, and the main toggle creation are left outside the toggle's callback function.
Everything Else Inside the Toggle: All functions, tasks, and additional variables are moved inside the toggle's callback function. This way, they are only defined and used when the toggle is activated.
Cleanup on Toggle Off: When the toggle is turned off, getgenv().AutoAll and getgenv().InstaKill are set to false, effectively stopping the loops. You can add any additional cleanup code if needed.
This should meet your requirement of encapsulating most of the script inside the toggle, leaving only the most important variables outside. Let me know if you need any further adjustments!