Add a good and aesthetic GUI to this: ` --[[ Super Advanced Auto Block Script for Saber…
- User
Add a good and aesthetic GUI to this:
code - Assistant
Add a good and aesthetic GUI to this:
--[[
Super Advanced Auto Block Script for Saber Showdown
Further Optimized for Enhanced Performance, Efficiency, and Maintainability
- Consistently blocks slap attacks within close proximity
- Enhanced throttling to prevent excessive blocking
- Consistent block direction updater
- Further optimized for performance and reduced computational overhead
- Streamlined code structure for better maintainability
--]]
-- === Services ===
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local VirtualInputManager = game:GetService("VirtualInputManager")
local CollectionService = game:GetService("CollectionService")
local Debris = game:GetService("Debris")
local Workspace = workspace
-- === Constants ===
local LOCAL_PLAYER = Players.LocalPlayer
local CAMERA = Workspace.CurrentCamera
local ATTACK_HITBOX_TAG = "AttackHitbox"
local BLOCK_DIRECTIONS = {
Forward = 1,
Right = 2,
Backward = 3,
Left = 4
}
-- === Remotes ===
local LightsaberRemotes = ReplicatedStorage:WaitForChild("LightsaberRemotes")
local BlockRemote = LightsaberRemotes:WaitForChild("Block")
local UnblockRemote = LightsaberRemotes:WaitForChild("Unblock")
local UpdateBlockDirectionRemote = LightsaberRemotes:WaitForChild("UpdateBlockDirection")
-- === Settings ===
local Settings = {
-- Blocking Settings
blockDistances = { -- Max distance to attempt a block per attack type
Slap = 10, -- Slaps require closer proximity
Default = 15 -- Default distance for other attacks
},
autoBlockEnabled = true, -- Enable/Disable dynamic auto-blocking
blockCooldown = 0.5, -- General cooldown between blocks (seconds)
attackBlockCooldowns = { -- Cooldown between blocks per attack type (seconds)
Slap = 0.2,
Default = 0.5
},
attackTypes = { -- Attack animation IDs
Slap = 12625891544,
SlappedLegs = 12671715182,
SlappedArms = 12625896358,
Punch = 12625897000, -- Example attack ID
Kick = 12625897500, -- Example attack ID
KickUp = 12625897944, -- Added KickUp
KickBack = 12625899752 -- Added KickBack
},
-- Counter Attacking Settings
autoCounterEnabled = true, -- Enable/Disable auto counter attacks
autoCounterDistance = 10, -- Distance within which to auto counter
counterCooldown = 1.5, -- Cooldown between counters (seconds)
counterKey = Enum.KeyCode.E, -- Key to use for countering
-- Reaction Settings
reactionTimeThreshold = 0.2, -- Threshold for reaction time (in seconds)
predictionFactor = 0.5, -- Factor for predicting enemy movements (0-1)
-- Slap Lag Handling
slapLagCompensation = 0.2, -- Additional delay to compensate for lag in slap attacks
-- Aim-Lock Directional Block Settings
aimLockEnabled = true, -- Enable/Disable aim-lock directional blocking
aimLockSmoothness = 0.1, -- Smoothness factor for direction adjustment
-- UI Settings
ui = {
ScreenGuiName = "AutoBlockUI",
BlackBoxSize = UDim2.new(0.25, 0, 0.1, 0),
BlackBoxPosition = UDim2.new(0, 0, 0.9, 0),
BlackBoxColor = Color3.fromRGB(0, 0, 0),
BlackBoxTransparency = 0.5,
LoadingBarSize = UDim2.new(1, 0, 0.2, 0),
LoadingBarPosition = UDim2.new(0, 0, -0.2, 0),
LoadingBarColorActive = Color3.fromRGB(0, 255, 0),
LoadingBarColorInactive = Color3.fromRGB(255, 0, 0),
LoadingBarTransparency = 0.3,
MessageBoxTextActive = "Blocking Active",
MessageBoxTextInactive = "Press 'Q' to toggle Auto Block",
MessageBoxColor = Color3.fromRGB(255, 255, 255),
MessageBoxTransparency = 1,
},
-- Debris Settings
debrisLifetime = 300, -- Time in seconds before debris is removed (e.g., hitboxes)
}
-- === Inverse Mapping for Attack Types ===
local attackTypesInverse = {}
for attack, id in pairs(Settings.attackTypes) do
attackTypesInverse[id] = attack
end
-- === State Tracking ===
local State = {
isBlocking = false,
lastBlockTime = {}, -- [player.UserId] = timestamp
lastCounterTime = {}, -- [player.UserId] = timestamp
currentBlockDirection = BLOCK_DIRECTIONS.Forward
}
-- === UI Elements ===
local UI = {
ScreenGui = nil,
BlackBox = nil,
LoadingBar = nil,
MessageBox = nil
}
-- === Helper Functions ===
-- Utility: Print with timestamp
local function debugPrint(message)
print(string.format("[%s] %s", os.date("%H:%M:%S"), message))
end
-- UI: Setup the User Interface
local function setupUI()
local screenGui = Instance.new("ScreenGui")
screenGui.Name = Settings.ui.ScreenGuiName
screenGui.Parent = LOCAL_PLAYER:WaitForChild("PlayerGui")
screenGui.ResetOnSpawn = false
screenGui.DisplayOrder = 1000 -- Ensure it's on top
-- Black Box Frame
local blackBox = Instance.new("Frame")
blackBox.Size = Settings.ui.BlackBoxSize
blackBox.Position = Settings.ui.BlackBoxPosition
blackBox.BackgroundColor3 = Settings.ui.BlackBoxColor
blackBox.BackgroundTransparency = Settings.ui.BlackBoxTransparency
blackBox.BorderSizePixel = 0
blackBox.Parent = screenGui
-- Loading Bar
local loadingBar = Instance.new("Frame")
loadingBar.Size = Settings.ui.LoadingBarSize
loadingBar.Position = Settings.ui.LoadingBarPosition
loadingBar.BackgroundColor3 = Settings.ui.LoadingBarColorInactive
loadingBar.BackgroundTransparency = Settings.ui.LoadingBarTransparency
loadingBar.BorderSizePixel = 0
loadingBar.Parent = blackBox
-- Message Box
local messageBox = Instance.new("TextLabel")
messageBox.Size = UDim2.new(1, 0, 1, 0)
messageBox.Position = UDim2.new(0, 0, 0, 0)
messageBox.BackgroundTransparency = Settings.ui.MessageBoxTransparency
messageBox.TextColor3 = Settings.ui.MessageBoxColor
messageBox.TextScaled = true
messageBox.Text = Settings.ui.MessageBoxTextInactive
messageBox.BorderSizePixel = 0
messageBox.Parent = blackBox
UI.ScreenGui = screenGui
UI.BlackBox = blackBox
UI.LoadingBar = loadingBar
UI.MessageBox = messageBox
end
-- Blocking: Start Blocking
local function startBlocking()
if not State.isBlocking then
State.isBlocking = true
BlockRemote:FireServer()
UI.MessageBox.Text = Settings.ui.MessageBoxTextActive
UI.LoadingBar.BackgroundColor3 = Settings.ui.LoadingBarColorActive
debugPrint("Blocking started")
end
end
-- Blocking: Stop Blocking
local function stopBlocking()
if State.isBlocking then
State.isBlocking = false
UnblockRemote:FireServer()
UI.MessageBox.Text = Settings.ui.MessageBoxTextInactive
UI.LoadingBar.BackgroundColor3 = Settings.ui.LoadingBarColorInactive
debugPrint("Blocking stopped")
end
end
-- Blocking: Toggle Blocking State
local function toggleBlocking()
if State.isBlocking then
stopBlocking()
else
startBlocking()
end
end
-- Prediction: Predict Enemy Movement
local function predictEnemyMovement(enemy)
local enemyCharacter = enemy.Character
if not enemyCharacter then return nil end
local enemyHRP = enemyCharacter:FindFirstChild("HumanoidRootPart")
if not enemyHRP then return nil end
local velocity = enemyHRP.Velocity
return enemyHRP.Position + (velocity * Settings.predictionFactor)
end
-- Direction: Get Hit Direction Based on Attacker Position
local function getHitDirection(attackerPosition, playerPosition, camLookVector, camRightVector)
local direction = (attackerPosition - playerPosition).Unit
local dotProduct = direction:Dot(camLookVector)
if Settings.aimLockEnabled then
if dotProduct > math.cos(math.rad(45)) then
return BLOCK_DIRECTIONS.Forward
elseif dotProduct < -math.cos(math.rad(45)) then
return BLOCK_DIRECTIONS.Backward
else
return direction:Dot(camRightVector) > 0 and BLOCK_DIRECTIONS.Right or BLOCK_DIRECTIONS.Left
end
else
local angle = math.deg(math.atan2(direction.Z, direction.X)) % 360
if angle < 45 or angle >= 315 then
return BLOCK_DIRECTIONS.Forward
elseif angle < 135 then
return BLOCK_DIRECTIONS.Right
elseif angle < 225 then
return BLOCK_DIRECTIONS.Backward
else
return BLOCK_DIRECTIONS.Left
end
end
end
-- Direction: Update Block Direction
local function updateBlockDirection(attackerPosition)
local playerCharacter = LOCAL_PLAYER.Character
if not playerCharacter then return BLOCK_DIRECTIONS.Forward end
local playerHRP = playerCharacter:FindFirstChild("HumanoidRootPart")
if not playerHRP then return BLOCK_DIRECTIONS.Forward end
local playerPosition = playerHRP.Position
local camCFrame = CAMERA.CFrame
local camLookVector = camCFrame.LookVector
local camRightVector = camCFrame.RightVector
local desiredDirection = getHitDirection(attackerPosition, playerPosition, camLookVector, camRightVector)
if desiredDirection ~= State.currentBlockDirection then
State.currentBlockDirection = desiredDirection
UpdateBlockDirectionRemote:FireServer(desiredDirection)
debugPrint(string.format("Block direction updated to %s", desiredDirection))
end
return desiredDirection
end
-- Counter Attacking: Perform Auto Counter
local function performAutoCounter(attacker)
local attackerId = attacker.UserId
local currentTime = tick()
if State.lastCounterTime[attackerId] and (currentTime - State.lastCounterTime[attackerId]) < Settings.counterCooldown then
return
end
-- Perform counter attack
VirtualInputManager:SendKeyEvent(true, Settings.counterKey, false, game)
task.delay(0.05, function()
VirtualInputManager:SendKeyEvent(false, Settings.counterKey, false, game)
end)
State.lastCounterTime[attackerId] = currentTime
debugPrint("Auto counter performed against " .. attacker.Name)
end
-- Blocking: Handle Incoming Hit with Enhanced Proximity and Throttling
local function handleIncomingHit(attacker, attackerPosition, attackType)
local attackerId = attacker.UserId
local currentTime = tick()
-- Determine appropriate cooldown and distance based on attack type
local cooldown = Settings.attackBlockCooldowns[attackType] or Settings.blockCooldown
local maxDistance = Settings.blockDistances[attackType] or Settings.blockDistances.Default
-- Check for cooldown
if State.lastBlockTime[attackerId] and (currentTime - State.lastBlockTime[attackerId]) < cooldown then
return
end
-- Check distance
local playerCharacter = LOCAL_PLAYER.Character
if not playerCharacter then return end
local playerHRP = playerCharacter.HumanoidRootPart -- Cached access
if not playerHRP then return end
local distance = (playerHRP.Position - attackerPosition).Magnitude
if distance > maxDistance then
return
end
-- Update last block time for throttling
State.lastBlockTime[attackerId] = currentTime
-- Determine if the attack is a slap for specific handling
local isSlap = (attackType == "Slap")
-- Determine reaction delay
local reactionDelay = isSlap and Settings.slapLagCompensation or Settings.reactionTimeThreshold
task.delay(reactionDelay, function()
updateBlockDirection(attackerPosition)
startBlocking()
-- Schedule unblocking with different delays based on attack type
local unblockDelay = isSlap and Settings.slapLagCompensation or 0.5
task.delay(unblockDelay, stopBlocking)
end)
-- Handle Auto Countering if enabled and within counter distance
if Settings.autoCounterEnabled and distance <= Settings.autoCounterDistance then
performAutoCounter(attacker)
end
end
-- Attack Detection: Handle Animation Played
local function onAnimationPlayed(animTrack, opponentPlayer)
local anim = animTrack.Animation
if not anim then return end
local animId = anim.AnimationId
if not animId then return end
-- Extract numeric ID from AnimationId
local numericAnimId = tonumber(animId:match("rbxassetid://(%d+)"))
if not numericAnimId then return end
local attackType = attackTypesInverse[numericAnimId]
if not attackType then return end
debugPrint(string.format("Detected attack '%s' from %s", attackType, opponentPlayer.Name))
local attackerCharacter = opponentPlayer.Character
if not attackerCharacter then return end
local attackerHRP = attackerCharacter.HumanoidRootPart
if not attackerHRP then return end
handleIncomingHit(opponentPlayer, attackerHRP.Position, attackType)
end
-- Animation Monitoring: Connect Animation Events
local function monitorAnimations(character, opponentPlayer)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local connection
connection = humanoid.AnimationPlayed:Connect(function(animTrack)
onAnimationPlayed(animTrack, opponentPlayer)
end)
-- Cleanup when character is removed
character.AncestryChanged:Connect(function(_, parent)
if not parent and connection then
connection:Disconnect()
end
end)
end
-- Hitbox Detection: Handle Hitbox Touched
local function onHitboxTouched(part, attackerPlayer)
if not part or attackerPlayer == LOCAL_PLAYER then return end
local attackerCharacter = part.Parent
if not attackerCharacter then return end
local attackerHRP = attackerCharacter:FindFirstChild("HumanoidRootPart")
if attackerHRP then
debugPrint("Hitbox detected attack from " .. attackerPlayer.Name)
handleIncomingHit(attackerPlayer, attackerHRP.Position, "Default") -- Assuming 'Default' for non-slap attacks
end
end
-- Hitbox Monitoring: Connect Hitbox Events
local function monitorHitboxes(character, attackerPlayer)
local hitboxes = CollectionService:GetTagged(ATTACK_HITBOX_TAG)
for _, hitbox in ipairs(hitboxes) do
if hitbox:IsDescendantOf(character) then
local connection
connection = hitbox.Touched:Connect(function(hitPart)
onHitboxTouched(hitPart, attackerPlayer)
end)
-- Cleanup when hitbox is removed
hitbox.AncestryChanged:Connect(function(_, parent)
if not parent and connection then
connection:Disconnect()
end
end)
-- Remove hitbox after specified time to prevent memory leaks
Debris:AddItem(hitbox, Settings.debrisLifetime)
end
end
end
-- Advanced Reaction System: Continuous Monitoring with Throttling
local function advancedReactionAutoBlock()
if not Settings.autoBlockEnabled then return end
local heartbeatThrottle = 0.05 -- Run logic every 0.05 seconds (20 times per second)
local accumulatedTime = 0
RunService.Heartbeat:Connect(function(deltaTime)
accumulatedTime += deltaTime
if accumulatedTime < heartbeatThrottle then
return
end
accumulatedTime = accumulatedTime - heartbeatThrottle
local playerCharacter = LOCAL_PLAYER.Character
if not playerCharacter then return end
local playerHRP = playerCharacter:FindFirstChild("HumanoidRootPart")
if not playerHRP then return end
local playerPosition = playerHRP.Position
local camCFrame = CAMERA.CFrame
local camLookVector = camCFrame.LookVector
local camRightVector = camCFrame.RightVector
for _, plr in ipairs(Players:GetPlayers()) do
if plr == LOCAL_PLAYER or not plr.Character then continue end
local enemyCharacter = plr.Character
local enemyHRP = enemyCharacter:FindFirstChild("HumanoidRootPart")
if not enemyHRP then continue end
local distance = (playerPosition - enemyHRP.Position).Magnitude
-- Determine maximum relevant distance for this enemy based on attack types
local maxRelevantDistance = Settings.blockDistances.Default
for _, attackType in pairs(Settings.attackTypes) do
local attackDistance = Settings.blockDistances[attackType] or Settings.blockDistances.Default
if attackDistance > maxRelevantDistance then
maxRelevantDistance = attackDistance
end
end
if distance > maxRelevantDistance then continue end
-- Prediction and Direction Update
local predictedPosition = predictEnemyMovement(plr) or enemyHRP.Position
updateBlockDirection(predictedPosition)
local enemyHumanoid = enemyCharacter:FindFirstChildOfClass("Humanoid")
if not enemyHumanoid then continue end
-- Check for active attack animations
for _, animTrack in ipairs(enemyHumanoid:GetPlayingAnimationTracks()) do
local anim = animTrack.Animation
if not anim then continue end
local animId = anim.AnimationId
if not animId then continue end
local numericAnimId = tonumber(animId:match("rbxassetid://(%d+)"))
if not numericAnimId then continue end
local attackType = attackTypesInverse[numericAnimId]
if not attackType then continue end
-- Determine if the attack should be considered based on distance
local requiredDistance = Settings.blockDistances[attackType] or Settings.blockDistances.Default
if distance > requiredDistance then continue end
handleIncomingHit(plr, enemyHRP.Position, attackType)
end
end
end)
end
-- Player Monitoring: Handle New Players
local function onPlayerAdded(plr)
if plr == LOCAL_PLAYER then return end
local function onCharacterAdded(character)
monitorAnimations(character, plr)
monitorHitboxes(character, plr)
end
plr.CharacterAdded:Connect(onCharacterAdded)
-- Handle existing character
if plr.Character then
onCharacterAdded(plr.Character)
end
end
-- Initialize Player Monitoring
local function initializePlayerMonitoring()
for _, plr in ipairs(Players:GetPlayers()) do
onPlayerAdded(plr)
end
Players.PlayerAdded:Connect(onPlayerAdded)
end
-- UI Feedback & Directional Block Update
local function updateUIAndDirection()
-- Update UI based on blocking state
local isBlocking = State.isBlocking
UI.LoadingBar.BackgroundColor3 = isBlocking and Settings.ui.LoadingBarColorActive or Settings.ui.LoadingBarColorInactive
UI.MessageBox.Text = isBlocking and Settings.ui.MessageBoxTextActive or Settings.ui.MessageBoxTextInactive
-- Update Block Direction based on Aim-Lock
if Settings.aimLockEnabled and Settings.autoBlockEnabled and isBlocking then
local mouseX, mouseY = UserInputService:GetMouseLocation()
local mouseRay = CAMERA:ViewportPointToRay(mouseX, mouseY)
local playerCharacter = LOCAL_PLAYER.Character
if playerCharacter and playerCharacter:FindFirstChild("HumanoidRootPart") then
local targetPosition = playerCharacter.HumanoidRootPart.Position + (mouseRay.Direction * 10)
updateBlockDirection(targetPosition)
end
end
end
-- Input Handling: Manual Blocking Toggle
local function setupInputHandling()
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.Q then
toggleBlocking()
end
end)
end
-- Character Cleanup: Handle Character Death or Removal
local function onCharacterRemoved()
stopBlocking()
end
local function connectCharacterEvents(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Died:Connect(onCharacterRemoved)
end
character.AncestryChanged:Connect(function(_, parent)
if not parent then
stopBlocking()
end
end)
end
local function setupLocalPlayerCharacterMonitoring()
local function onLocalCharacterAdded(character)
connectCharacterEvents(character)
end
if LOCAL_PLAYER.Character then
connectCharacterEvents(LOCAL_PLAYER.Character)
end
LOCAL_PLAYER.CharacterAdded:Connect(onLocalCharacterAdded)
end
-- === Initialization ===
-- Setup UI
setupUI()
-- Setup Input Handling
setupInputHandling()
-- Initialize Player Monitoring
initializePlayerMonitoring()
-- Setup Local Player Character Monitoring
setupLocalPlayerCharacterMonitoring()
-- Setup Combined UI Feedback and Directional Block Update
RunService.RenderStepped:Connect(updateUIAndDirection)
-- Initialize Advanced Reaction System
advancedReactionAutoBlock()
-- Notify that the script is running
debugPrint("Advanced Auto Block Script is now running.")
Certainly! Let's enhance the existing GUI to make it more aesthetic and user-friendly. We'll introduce additional UI elements, better visual design, and improved feedback to the player. Here's a summary of the enhancements:
Below is the updated script with the enhanced GUI integrated:
--[[
Super Advanced Auto Block Script for Saber Showdown
Further Optimized for Enhanced Performance, Efficiency, and Maintainability
- Consistently blocks slap attacks within close proximity
- Enhanced throttling to prevent excessive blocking
- Consistent block direction updater
- Further optimized for performance and reduced computational overhead
- Streamlined code structure for better maintainability
- Enhanced Aesthetic GUI with modern design elements and additional features
--]]
-- === Services ===
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local VirtualInputManager = game:GetService("VirtualInputManager")
local CollectionService = game:GetService("CollectionService")
local Debris = game:GetService("Debris")
local Workspace = workspace
-- === Constants ===
local LOCAL_PLAYER = Players.LocalPlayer
local CAMERA = Workspace.CurrentCamera
local ATTACK_HITBOX_TAG = "AttackHitbox"
local BLOCK_DIRECTIONS = {
Forward = 1,
Right = 2,
Backward = 3,
Left = 4
}
-- === Remotes ===
local LightsaberRemotes = ReplicatedStorage:WaitForChild("LightsaberRemotes")
local BlockRemote = LightsaberRemotes:WaitForChild("Block")
local UnblockRemote = LightsaberRemotes:WaitForChild("Unblock")
local UpdateBlockDirectionRemote = LightsaberRemotes:WaitForChild("UpdateBlockDirection")
-- === Settings ===
local Settings = {
-- Blocking Settings
blockDistances = { -- Max distance to attempt a block per attack type
Slap = 10, -- Slaps require closer proximity
Default = 15 -- Default distance for other attacks
},
autoBlockEnabled = true, -- Enable/Disable dynamic auto-blocking
blockCooldown = 0.5, -- General cooldown between blocks (seconds)
attackBlockCooldowns = { -- Cooldown between blocks per attack type (seconds)
Slap = 0.2,
Default = 0.5
},
attackTypes = { -- Attack animation IDs
Slap = 12625891544,
SlappedLegs = 12671715182,
SlappedArms = 12625896358,
Punch = 12625897000, -- Example attack ID
Kick = 12625897500, -- Example attack ID
KickUp = 12625897944, -- Added KickUp
KickBack = 12625899752 -- Added KickBack
},
-- Counter Attacking Settings
autoCounterEnabled = true, -- Enable/Disable auto counter attacks
autoCounterDistance = 10, -- Distance within which to auto counter
counterCooldown = 1.5, -- Cooldown between counters (seconds)
counterKey = Enum.KeyCode.E, -- Key to use for countering
-- Reaction Settings
reactionTimeThreshold = 0.2, -- Threshold for reaction time (in seconds)
predictionFactor = 0.5, -- Factor for predicting enemy movements (0-1)
-- Slap Lag Handling
slapLagCompensation = 0.2, -- Additional delay to compensate for lag in slap attacks
-- Aim-Lock Directional Block Settings
aimLockEnabled = true, -- Enable/Disable aim-lock directional blocking
aimLockSmoothness = 0.1, -- Smoothness factor for direction adjustment
-- UI Settings
ui = {
ScreenGuiName = "AutoBlockUI",
-- Black Box Frame
BlackBox = {
Size = UDim2.new(0.3, 0, 0.15, 0),
Position = UDim2.new(0.35, 0, 0.85, 0),
BackgroundColor = Color3.fromRGB(30, 30, 30),
BackgroundTransparency = 0.2,
CornerRadius = 12,
BorderColor = Color3.fromRGB(255, 255, 255),
BorderSizePixel = 2
},
-- Loading Bar
LoadingBar = {
Size = UDim2.new(1, -20, 0.25, -10),
Position = UDim2.new(0, 10, 0.1, 10),
BackgroundColorActive = Color3.fromRGB(0, 255, 0),
BackgroundColorInactive = Color3.fromRGB(255, 0, 0),
BackgroundTransparency = 0.3,
CornerRadius = 8
},
-- Message Box
MessageBox = {
Size = UDim2.new(1, -20, 0.4, -10),
Position = UDim2.new(0, 10, 0.35, 10),
BackgroundTransparency = 1,
TextColor = Color3.fromRGB(255, 255, 255),
TextScaled = true,
Font = Enum.Font.GothamSemibold,
Text = "Press 'Q' to toggle Auto Block",
TextStrokeColor = Color3.fromRGB(0, 0, 0),
TextStrokeTransparency = 0.5
},
-- Direction Indicator
DirectionIndicator = {
Size = UDim2.new(0.2, -10, 0.5, -10),
Position = UDim2.new(0.4, 10, 0.5, 10),
BackgroundColor = Color3.fromRGB(50, 50, 50),
BackgroundTransparency = 0.3,
CornerRadius = 8,
Image = nil -- Placeholder for directional icons
},
-- Toggle Button
ToggleButton = {
Size = UDim2.new(0.3, -20, 0.25, -10),
Position = UDim2.new(0.35, 10, 0.7, 10),
BackgroundColor = Color3.fromRGB(70, 130, 180),
BackgroundTransparency = 0.3,
CornerRadius = 8,
TextColor = Color3.fromRGB(255, 255, 255),
TextScaled = true,
Font = Enum.Font.GothamBold,
Text = "Disable Auto Block",
TextStrokeColor = Color3.fromRGB(0, 0, 0),
TextStrokeTransparency = 0.5
}
},
-- Debris Settings
debrisLifetime = 300, -- Time in seconds before debris is removed (e.g., hitboxes)
}
-- === Inverse Mapping for Attack Types ===
local attackTypesInverse = {}
for attack, id in pairs(Settings.attackTypes) do
attackTypesInverse[id] = attack
end
-- === State Tracking ===
local State = {
isBlocking = false,
lastBlockTime = {}, -- [player.UserId] = timestamp
lastCounterTime = {}, -- [player.UserId] = timestamp
currentBlockDirection = BLOCK_DIRECTIONS.Forward,
autoBlockEnabled = Settings.autoBlockEnabled
}
-- === UI Elements ===
local UI = {
ScreenGui = nil,
BlackBox = nil,
LoadingBar = nil,
MessageBox = nil,
DirectionIndicator = nil,
ToggleButton = nil
}
-- === Helper Functions ===
-- Utility: Print with timestamp
local function debugPrint(message)
print(string.format("[%s] %s", os.date("%H:%M:%S"), message))
end
-- UI: Create Rounded Corners for Frames
local function addRoundedCorners(frame, radius)
local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, radius)
corner.Parent = frame
return corner
end
-- UI: Setup the User Interface
local function setupUI()
local screenGui = Instance.new("ScreenGui")
screenGui.Name = Settings.ui.ScreenGuiName
screenGui.Parent = LOCAL_PLAYER:WaitForChild("PlayerGui")
screenGui.ResetOnSpawn = false
screenGui.DisplayOrder = 1000 -- Ensure it's on top
-- Black Box Frame
local blackBox = Instance.new("Frame")
blackBox.Size = Settings.ui.BlackBox.Size
blackBox.Position = Settings.ui.BlackBox.Position
blackBox.BackgroundColor3 = Settings.ui.BlackBox.BackgroundColor
blackBox.BackgroundTransparency = Settings.ui.BlackBox.BackgroundTransparency
blackBox.BorderSizePixel = Settings.ui.BlackBox.BorderSizePixel
blackBox.BorderColor3 = Settings.ui.BlackBox.BorderColor
blackBox.Parent = screenGui
addRoundedCorners(blackBox, Settings.ui.BlackBox.CornerRadius)
-- Loading Bar
local loadingBar = Instance.new("Frame")
loadingBar.Size = Settings.ui.LoadingBar.Size
loadingBar.Position = Settings.ui.LoadingBar.Position
loadingBar.BackgroundColor3 = Settings.ui.LoadingBar.BackgroundColorInactive
loadingBar.BackgroundTransparency = Settings.ui.LoadingBar.BackgroundTransparency
loadingBar.BorderSizePixel = 0
loadingBar.Parent = blackBox
addRoundedCorners(loadingBar, 8)
-- Loading Bar Border
local loadingBarBorder = Instance.new("Frame")
loadingBarBorder.Size = loadingBar.Size
loadingBarBorder.Position = loadingBar.Position
loadingBarBorder.BackgroundTransparency = 1
loadingBarBorder.BorderSizePixel = 2
loadingBarBorder.BorderColor3 = Color3.fromRGB(255, 255, 255)
loadingBarBorder.Parent = blackBox
addRoundedCorners(loadingBarBorder, 8)
loadingBar.ZIndex = 2
-- Message Box
local messageBox = Instance.new("TextLabel")
messageBox.Size = Settings.ui.MessageBox.Size
messageBox.Position = Settings.ui.MessageBox.Position
messageBox.BackgroundTransparency = Settings.ui.MessageBox.BackgroundTransparency
messageBox.TextColor3 = Settings.ui.MessageBox.TextColor
messageBox.TextScaled = Settings.ui.MessageBox.TextScaled
messageBox.Text = Settings.ui.MessageBox.Text
messageBox.Font = Settings.ui.MessageBox.Font
messageBox.TextStrokeColor3 = Settings.ui.MessageBox.TextStrokeColor
messageBox.TextStrokeTransparency = Settings.ui.MessageBox.TextStrokeTransparency
messageBox.BorderSizePixel = 0
messageBox.Parent = blackBox
-- Direction Indicator
local directionIndicator = Instance.new("Frame")
directionIndicator.Size = Settings.ui.DirectionIndicator.Size
directionIndicator.Position = Settings.ui.DirectionIndicator.Position
directionIndicator.BackgroundColor3 = Settings.ui.DirectionIndicator.BackgroundColor
directionIndicator.BackgroundTransparency = Settings.ui.DirectionIndicator.BackgroundTransparency
directionIndicator.BorderSizePixel = 0
directionIndicator.Parent = blackBox
addRoundedCorners(directionIndicator, 8)
-- Direction Indicator Icon (Placeholder for actual images)
local directionIcon = Instance.new("ImageLabel")
directionIcon.Size = UDim2.new(0.8, 0, 0.8, 0)
directionIcon.Position = UDim2.new(0.1, 0, 0.1, 0)
directionIcon.BackgroundTransparency = 1
-- Placeholder: You can replace these with actual directional icons
directionIcon.Image = "rbxassetid://4542562196" -- Forward Arrow Icon
directionIcon.Visible = true
directionIcon.Parent = directionIndicator
-- Toggle Button
local toggleButton = Instance.new("TextButton")
toggleButton.Size = Settings.ui.ToggleButton.Size
toggleButton.Position = Settings.ui.ToggleButton.Position
toggleButton.BackgroundColor3 = Settings.ui.ToggleButton.BackgroundColor
toggleButton.BackgroundTransparency = Settings.ui.ToggleButton.BackgroundTransparency
toggleButton.BorderSizePixel = 0
toggleButton.TextColor3 = Settings.ui.ToggleButton.TextColor
toggleButton.TextScaled = Settings.ui.ToggleButton.TextScaled
toggleButton.Font = Settings.ui.ToggleButton.Font
toggleButton.Text = Settings.ui.ToggleButton.Text
toggleButton.TextStrokeColor3 = Settings.ui.ToggleButton.TextStrokeColor
toggleButton.TextStrokeTransparency = Settings.ui.ToggleButton.TextStrokeTransparency
toggleButton.Parent = blackBox
addRoundedCorners(toggleButton, 8)
-- Toggle Button Hover Effect
toggleButton.MouseEnter:Connect(function()
toggleButton.BackgroundColor3 = Color3.fromRGB(100, 149, 237)
end)
toggleButton.MouseLeave:Connect(function()
toggleButton.BackgroundColor3 = Settings.ui.ToggleButton.BackgroundColor
end)
-- Toggle Button Functionality
toggleButton.MouseButton1Click:Connect(function()
State.autoBlockEnabled = not State.autoBlockEnabled
toggleButton.Text = State.autoBlockEnabled and "Disable Auto Block" or "Enable Auto Block"
toggleButton.BackgroundColor3 = State.autoBlockEnabled and Settings.ui.ToggleButton.BackgroundColor or Color3.fromRGB(169, 169, 169)
debugPrint("Auto Block " .. (State.autoBlockEnabled and "Enabled" or "Disabled"))
end)
-- Assign UI Elements to the UI Table
UI.ScreenGui = screenGui
UI.BlackBox = blackBox
UI.LoadingBar = loadingBar
UI.MessageBox = messageBox
UI.DirectionIndicator = directionIndicator
UI.ToggleButton = toggleButton
end
-- Blocking: Start Blocking
local function startBlocking()
if not State.isBlocking then
State.isBlocking = true
BlockRemote:FireServer()
UI.MessageBox.Text = "Blocking Active"
UI.LoadingBar.BackgroundColor3 = Settings.ui.LoadingBar.BackgroundColorActive
debugPrint("Blocking started")
end
end
-- Blocking: Stop Blocking
local function stopBlocking()
if State.isBlocking then
State.isBlocking = false
UnblockRemote:FireServer()
UI.MessageBox.Text = "Auto Block Inactive"
UI.LoadingBar.BackgroundColor3 = Settings.ui.LoadingBar.BackgroundColorInactive
debugPrint("Blocking stopped")
end
end
-- Blocking: Toggle Blocking State
local function toggleBlocking()
if State.isBlocking then
stopBlocking()
else
startBlocking()
end
end
-- Prediction: Predict Enemy Movement
local function predictEnemyMovement(enemy)
local enemyCharacter = enemy.Character
if not enemyCharacter then return nil end
local enemyHRP = enemyCharacter:FindFirstChild("HumanoidRootPart")
if not enemyHRP then return nil end
local velocity = enemyHRP.Velocity
return enemyHRP.Position + (velocity * Settings.predictionFactor)
end
-- Direction: Get Hit Direction Based on Attacker Position
local function getHitDirection(attackerPosition, playerPosition, camLookVector, camRightVector)
local direction = (attackerPosition - playerPosition).Unit
local dotProduct = direction:Dot(camLookVector)
if Settings.aimLockEnabled then
if dotProduct > math.cos(math.rad(45)) then
return BLOCK_DIRECTIONS.Forward
elseif dotProduct < -math.cos(math.rad(45)) then
return BLOCK_DIRECTIONS.Backward
else
return direction:Dot(camRightVector) > 0 and BLOCK_DIRECTIONS.Right or BLOCK_DIRECTIONS.Left
end
else
local angle = math.deg(math.atan2(direction.Z, direction.X)) % 360
if angle < 45 or angle >= 315 then
return BLOCK_DIRECTIONS.Forward
elseif angle < 135 then
return BLOCK_DIRECTIONS.Right
elseif angle < 225 then
return BLOCK_DIRECTIONS.Backward
else
return BLOCK_DIRECTIONS.Left
end
end
end
-- Direction: Update Block Direction
local function updateBlockDirection(attackerPosition)
local playerCharacter = LOCAL_PLAYER.Character
if not playerCharacter then return BLOCK_DIRECTIONS.Forward end
local playerHRP = playerCharacter:FindFirstChild("HumanoidRootPart")
if not playerHRP then return BLOCK_DIRECTIONS.Forward end
local playerPosition = playerHRP.Position
local camCFrame = CAMERA.CFrame
local camLookVector = camCFrame.LookVector
local camRightVector = camCFrame.RightVector
local desiredDirection = getHitDirection(attackerPosition, playerPosition, camLookVector, camRightVector)
if desiredDirection ~= State.currentBlockDirection then
State.currentBlockDirection = desiredDirection
UpdateBlockDirectionRemote:FireServer(desiredDirection)
debugPrint(string.format("Block direction updated to %s", desiredDirection))
-- Update Direction Indicator
local directionIcons = {
[BLOCK_DIRECTIONS.Forward] = "rbxassetid://4542562196", -- Forward Arrow Icon
[BLOCK_DIRECTIONS.Right] = "rbxassetid://4542562196", -- Replace with Right Arrow Icon
[BLOCK_DIRECTIONS.Backward] = "rbxassetid://4542562196", -- Replace with Backward Arrow Icon
[BLOCK_DIRECTIONS.Left] = "rbxassetid://4542562196" -- Replace with Left Arrow Icon
}
-- TODO: Replace all with corresponding directional icons
UI.DirectionIndicator:FindFirstChildOfClass("ImageLabel").Image = directionIcons[desiredDirection] or directionIcons[BLOCK_DIRECTIONS.Forward]
end
return desiredDirection
end
-- Counter Attacking: Perform Auto Counter
local function performAutoCounter(attacker)
local attackerId = attacker.UserId
local currentTime = tick()
if State.lastCounterTime[attackerId] and (currentTime - State.lastCounterTime[attackerId]) < Settings.counterCooldown then
return
end
-- Perform counter attack
VirtualInputManager:SendKeyEvent(true, Settings.counterKey, false, game)
task.delay(0.05, function()
VirtualInputManager:SendKeyEvent(false, Settings.counterKey, false, game)
end)
State.lastCounterTime[attackerId] = currentTime
debugPrint("Auto counter performed against " .. attacker.Name)
end
-- Blocking: Handle Incoming Hit with Enhanced Proximity and Throttling
local function handleIncomingHit(attacker, attackerPosition, attackType)
local attackerId = attacker.UserId
local currentTime = tick()
-- Determine appropriate cooldown and distance based on attack type
local cooldown = Settings.attackBlockCooldowns[attackType] or Settings.blockCooldown
local maxDistance = Settings.blockDistances[attackType] or Settings.blockDistances.Default
-- Check for cooldown
if State.lastBlockTime[attackerId] and (currentTime - State.lastBlockTime[attackerId]) < cooldown then
return
end
-- Check distance
local playerCharacter = LOCAL_PLAYER.Character
if not playerCharacter then return end
local playerHRP = playerCharacter.HumanoidRootPart -- Cached access
if not playerHRP then return end
local distance = (playerHRP.Position - attackerPosition).Magnitude
if distance > maxDistance then
return
end
-- Update last block time for throttling
State.lastBlockTime[attackerId] = currentTime
-- Determine if the attack is a slap for specific handling
local isSlap = (attackType == "Slap")
-- Determine reaction delay
local reactionDelay = isSlap and Settings.slapLagCompensation or Settings.reactionTimeThreshold
task.delay(reactionDelay, function()
updateBlockDirection(attackerPosition)
startBlocking()
-- Schedule unblocking with different delays based on attack type
local unblockDelay = isSlap and Settings.slapLagCompensation or 0.5
task.delay(unblockDelay, stopBlocking)
end)
-- Handle Auto Countering if enabled and within counter distance
if Settings.autoCounterEnabled and distance <= Settings.autoCounterDistance and State.autoBlockEnabled then
performAutoCounter(attacker)
end
end
-- Attack Detection: Handle Animation Played
local function onAnimationPlayed(animTrack, opponentPlayer)
local anim = animTrack.Animation
if not anim then return end
local animId = anim.AnimationId
if not animId then return end
-- Extract numeric ID from AnimationId
local numericAnimId = tonumber(animId:match("rbxassetid://(%d+)"))
if not numericAnimId then return end
local attackType = attackTypesInverse[numericAnimId]
if not attackType then return end
debugPrint(string.format("Detected attack '%s' from %s", attackType, opponentPlayer.Name))
local attackerCharacter = opponentPlayer.Character
if not attackerCharacter then return end
local attackerHRP = attackerCharacter.HumanoidRootPart
if not attackerHRP then return end
handleIncomingHit(opponentPlayer, attackerHRP.Position, attackType)
end
-- Animation Monitoring: Connect Animation Events
local function monitorAnimations(character, opponentPlayer)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local connection
connection = humanoid.AnimationPlayed:Connect(function(animTrack)
onAnimationPlayed(animTrack, opponentPlayer)
end)
-- Cleanup when character is removed
character.AncestryChanged:Connect(function(_, parent)
if not parent and connection then
connection:Disconnect()
end
end)
end
-- Hitbox Detection: Handle Hitbox Touched
local function onHitboxTouched(part, attackerPlayer)
if not part or attackerPlayer == LOCAL_PLAYER then return end
local attackerCharacter = part.Parent
if not attackerCharacter then return end
local attackerHRP = attackerCharacter.HumanoidRootPart
if attackerHRP then
debugPrint("Hitbox detected attack from " .. attackerPlayer.Name)
handleIncomingHit(attackerPlayer, attackerHRP.Position, "Default") -- Assuming 'Default' for non-slap attacks
end
end
-- Hitbox Monitoring: Connect Hitbox Events
local function monitorHitboxes(character, attackerPlayer)
local hitboxes = CollectionService:GetTagged(ATTACK_HITBOX_TAG)
for _, hitbox in ipairs(hitboxes) do
if hitbox:IsDescendantOf(character) then
local connection
connection = hitbox.Touched:Connect(function(hitPart)
onHitboxTouched(hitPart, attackerPlayer)
end)
-- Cleanup when hitbox is removed
hitbox.AncestryChanged:Connect(function(_, parent)
if not parent and connection then
connection:Disconnect()
end
end)
-- Remove hitbox after specified time to prevent memory leaks
Debris:AddItem(hitbox, Settings.debrisLifetime)
end
end
end
-- Advanced Reaction System: Continuous Monitoring with Throttling
local function advancedReactionAutoBlock()
if not Settings.autoBlockEnabled then return end
local heartbeatThrottle = 0.05 -- Run logic every 0.05 seconds (20 times per second)
local accumulatedTime = 0
RunService.Heartbeat:Connect(function(deltaTime)
accumulatedTime += deltaTime
if accumulatedTime < heartbeatThrottle then
return
end
accumulatedTime = accumulatedTime - heartbeatThrottle
if not State.autoBlockEnabled then return end
local playerCharacter = LOCAL_PLAYER.Character
if not playerCharacter then return end
local playerHRP = playerCharacter:FindFirstChild("HumanoidRootPart")
if not playerHRP then return end
local playerPosition = playerHRP.Position
local camCFrame = CAMERA.CFrame
local camLookVector = camCFrame.LookVector
local camRightVector = camCFrame.RightVector
for _, plr in ipairs(Players:GetPlayers()) do
if plr == LOCAL_PLAYER or not plr.Character then continue end
local enemyCharacter = plr.Character
local enemyHRP = enemyCharacter:FindFirstChild("HumanoidRootPart")
if not enemyHRP then continue end
local distance = (playerPosition - enemyHRP.Position).Magnitude
-- Determine maximum relevant distance for this enemy based on attack types
local maxRelevantDistance = Settings.blockDistances.Default
for _, attackType in pairs(Settings.attackTypes) do
local attackDistance = Settings.blockDistances[attackType] or Settings.blockDistances.Default
if attackDistance > maxRelevantDistance then
maxRelevantDistance = attackDistance
end
end
if distance > maxRelevantDistance then continue end
-- Prediction and Direction Update
local predictedPosition = predictEnemyMovement(plr) or enemyHRP.Position
updateBlockDirection(predictedPosition)
local enemyHumanoid = enemyCharacter:FindFirstChildOfClass("Humanoid")
if not enemyHumanoid then continue end
-- Check for active attack animations
for _, animTrack in ipairs(enemyHumanoid:GetPlayingAnimationTracks()) do
local anim = animTrack.Animation
if not anim then continue end
local animId = anim.AnimationId
if not animId then continue end
local numericAnimId = tonumber(animId:match("rbxassetid://(%d+)"))
if not numericAnimId then continue end
local attackType = attackTypesInverse[numericAnimId]
if not attackType then continue end
-- Determine if the attack should be considered based on distance
local requiredDistance = Settings.blockDistances[attackType] or Settings.blockDistances.Default
if distance > requiredDistance then continue end
handleIncomingHit(plr, enemyHRP.Position, attackType)
end
end
end)
end
-- Player Monitoring: Handle New Players
local function onPlayerAdded(plr)
if plr == LOCAL_PLAYER then return end
local function onCharacterAdded(character)
monitorAnimations(character, plr)
monitorHitboxes(character, plr)
end
plr.CharacterAdded:Connect(onCharacterAdded)
-- Handle existing character
if plr.Character then
onCharacterAdded(plr.Character)
end
end
-- Initialize Player Monitoring
local function initializePlayerMonitoring()
for _, plr in ipairs(Players:GetPlayers()) do
onPlayerAdded(plr)
end
Players.PlayerAdded:Connect(onPlayerAdded)
end
-- UI Feedback & Directional Block Update
local function updateUIAndDirection()
-- Update UI based on blocking state
local isBlocking = State.isBlocking
UI.LoadingBar.BackgroundColor3 = isBlocking and Settings.ui.LoadingBar.BackgroundColorActive or Settings.ui.LoadingBar.BackgroundColorInactive
UI.MessageBox.Text = isBlocking and "Blocking Active" or (State.autoBlockEnabled and "Auto Block Enabled" or "Auto Block Disabled")
-- Update Block Direction based on Aim-Lock
if Settings.aimLockEnabled and Settings.autoBlockEnabled and isBlocking then
local mouseX, mouseY = UserInputService:GetMouseLocation()
local mouseRay = CAMERA:ViewportPointToRay(mouseX, mouseY)
local playerCharacter = LOCAL_PLAYER.Character
if playerCharacter and playerCharacter:FindFirstChild("HumanoidRootPart") then
local targetPosition = playerCharacter.HumanoidRootPart.Position + (mouseRay.Direction * 10)
updateBlockDirection(targetPosition)
end
end
end
-- Input Handling: Manual Blocking Toggle
local function setupInputHandling()
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.Q then
toggleBlocking()
end
end)
end
-- Character Cleanup: Handle Character Death or Removal
local function onCharacterRemoved()
stopBlocking()
end
local function connectCharacterEvents(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Died:Connect(onCharacterRemoved)
end
character.AncestryChanged:Connect(function(_, parent)
if not parent then
stopBlocking()
end
end)
end
local function setupLocalPlayerCharacterMonitoring()
local function onLocalCharacterAdded(character)
connectCharacterEvents(character)
end
if LOCAL_PLAYER.Character then
connectCharacterEvents(LOCAL_PLAYER.Character)
end
LOCAL_PLAYER.CharacterAdded:Connect(onLocalCharacterAdded)
end
-- === Initialization ===
-- Setup UI
setupUI()
-- Setup Input Handling
setupInputHandling()
-- Initialize Player Monitoring
initializePlayerMonitoring()
-- Setup Local Player Character Monitoring
setupLocalPlayerCharacterMonitoring()
-- Setup Combined UI Feedback and Directional Block Update
RunService.RenderStepped:Connect(updateUIAndDirection)
-- Initialize Advanced Reaction System
advancedReactionAutoBlock()
-- Notify that the script is running
debugPrint("Advanced Auto Block Script with Enhanced GUI is now running.")
UICorner instances to frames for smooth, rounded edges.ImageLabel within the DirectionIndicator frame to display directional arrows. You can replace the placeholder image IDs (rbxassetid://4542562196) with actual directional icons.updateBlockDirection function updates the directional icon based on the current block direction.ToggleButton that allows players to enable or disable the auto-block feature directly from the UI.UDim2) to ensure the GUI looks good on various resolutions.addRoundedCorners to avoid repetitive code and keep the script clean.Directional Icons: Replace the placeholder image IDs with actual arrow icons representing forward, right, backward, and left directions. Upload your custom images to Roblox and use their asset IDs.
Colors and Styles: Feel free to adjust colors, transparency levels, and other style elements in the Settings.ui table to better match your game's theme.
Additional UI Elements: You can expand the GUI further by adding cooldown timers, progress bars, or other indicators as needed.
Animations: To make the GUI more dynamic, consider adding animations (e.g., fade-ins, slide-ins) using TweenService for transitions between states.
Localization: If your game supports multiple languages, implement localization for the text elements to cater to a broader audience.
The enhanced GUI not only improves the visual appeal but also adds practical features that make the script more user-friendly. By integrating these changes, players can have a better experience with clear indicators and control over the auto-block functionality. Feel free to tweak and expand upon these enhancements to best fit your game's unique requirements!
Not yet included in a published release.