o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
Further Optimize this: [code] Reference Links:…
- User
Further Optimize this:
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") local VirtualInputManager = game:GetService("VirtualInputManager") local LightsaberRemotes = ReplicatedStorage:WaitForChild("LightsaberRemotes") local BlockRemote = LightsaberRemotes:WaitForChild("Block") local UnblockRemote = LightsaberRemotes:WaitForChild("Unblock") -- Settings local blockDistance = 15 -- Adjust this to determine how close the opponent must be for a block local autoCounterEnabled = true local autoSlapDistance = 10 -- Distance to counter slap local lastBlockTime = 0 local blockCooldown = 1 -- Cooldown between blocks -- Check if animation is a slap local slapAnimations = { ["Slap"] = 12625891544, ["SlappedLegs"] = 12671715182, ["SlappedArms"] = 12625896358 } -- Block and counter slap local function handleSlapAnimation(opponent, animTrack) local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoidRootPart = character:WaitForChild("HumanoidRootPart") -- Check the distance between the local player and opponent local opponentRootPart = opponent.Character:FindFirstChild("HumanoidRootPart") if opponentRootPart then local distance = (humanoidRootPart.Position - opponentRootPart.Position).Magnitude if distance <= blockDistance then -- Block the slap BlockRemote:FireServer() task.wait(animTrack.Length) -- Hold the block for the slap animation duration UnblockRemote:FireServer() -- Automatically counter slap if within slap range if autoCounterEnabled and distance <= autoSlapDistance then VirtualInputManager:SendKeyEvent(true, Enum.KeyCode.E, false, game) task.wait(0.1) VirtualInputManager:SendKeyEvent(false, Enum.KeyCode.E, false, game) end end end end -- Track opponent animation local function onCharacterAdded(character) local humanoid = character:WaitForChild("Humanoid") local player = Players:GetPlayerFromCharacter(character) humanoid.AnimationPlayed:Connect(function(animTrack) for animName, animId in pairs(slapAnimations) do if animTrack.Animation.AnimationId == "rbxassetid://" .. animId then handleSlapAnimation(player, animTrack) break end end end) end -- Monitor all players for _, player in ipairs(Players:GetPlayers()) do if player.Character then onCharacterAdded(player.Character) end player.CharacterAdded:Connect(onCharacterAdded) end Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(onCharacterAdded) end)Reference Links:
https://raw.githubusercontent.com/Synarcy/SaberShowdown/refs/heads/main/AutoBlockSS.lua
- Assistant