rework and enhance 3x this script, and remove all comments local character =…
- User
rework and enhance 3x this script, and remove all comments local character = script.Parent local humanoid = character:WaitForChild("Humanoid") local rootPart = character:WaitForChild("HumanoidRootPart") local head = character:WaitForChild("Head")
local TweenService = game:GetService("TweenService") local PathfindingService = game:GetService("PathfindingService") local ReplicatedStorage = game:GetService("ReplicatedStorage")
local currentMode = 1 local modeChangeCooldown = 5 -- seconds local soundPlayChance = 0.2 -- 20% chance to play a sound each iteration local lifespanDuration = 10 -- seconds local spawnTime = tick()
local function getRandomPosition() local randomAngle = math.random() * math.pi * 2 local randomDistance = math.random(10, 30) local newX = rootPart.Position.X + math.cos(randomAngle) * randomDistance local newZ = rootPart.Position.Z + math.sin(randomAngle) * randomDistance return Vector3.new(newX, rootPart.Position.Y, newZ) end
local function getNearbyPlayers(maxDistance) local nearbyPlayers = {} for _, player in pairs(game.Players:GetPlayers()) do if player.Character and player.Character ~= character then local distance = (player.Character.HumanoidRootPart.Position - rootPart.Position).Magnitude if distance <= maxDistance then table.insert(nearbyPlayers, player.Character) end end end return nearbyPlayers end
local function getNearestPlayer() local nearestPlayer = nil local nearestDistance = math.huge
for _, player in pairs(game.Players:GetPlayers()) do if player.Character and player.Character ~= character then local distance = (player.Character.HumanoidRootPart.Position - rootPart.Position).Magnitude if distance < nearestDistance then nearestDistance = distance nearestPlayer = player.Character end end end return nearestPlayerend
local function moveToPosition(targetPosition) local path = PathfindingService:CreatePath() path:ComputeAsync(rootPart.Position, targetPosition)
if path.Status == Enum.PathStatus.Success then local waypoints = path:GetWaypoints() for i, waypoint in ipairs(waypoints) do if waypoint.Action == Enum.PathWaypointAction.Jump then humanoid.Jump = true end humanoid:MoveTo(waypoint.Position) humanoid.MoveToFinished:Wait() end endend
local function tweenLookAt(targetPosition, duration) local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) local startCFrame = rootPart.CFrame local endCFrame = CFrame.new(rootPart.Position, Vector3.new(targetPosition.X, rootPart.Position.Y, targetPosition.Z))
local tween = TweenService:Create(rootPart, tweenInfo, {CFrame = endCFrame}) tween:Play() tween.Completed:Wait()end
local function lookAtRandomNearbyPlayer() local nearbyPlayers = getNearbyPlayers(50) -- Adjust the max distance as needed if #nearbyPlayers > 0 then local randomPlayer = nearbyPlayers[math.random(1, #nearbyPlayers)] tweenLookAt(randomPlayer.HumanoidRootPart.Position, 0.5) end end
- Assistant