JIT
Guest player immobilizes and kills
ضيف ان يحلق لاعب واذا لمس لاعب لا يمكن للاعب يتحرك ويقتل لاعب بععد 0.8 ثانية
Updated files
v1
عفوا نسيت اني اوريك سركبت local npc = script.Parent local humanoid = npc:WaitForChild("Humanoid") local rootPart = npc:WaitForChild("HumanoidRootPart") local animator = humanoid:WaitForChild("Animator") local Players = game:GetService("Players") local INTERACTION_COOLDOWN = 999 -- مدة الكول داون local WALK_ANIMATION_ID = "rbxassetid://139807428535351" -- استبدل بالـ ID الخاص بأنيميشن المشي local INTERACTION_ANIMATION_ID = "rbxassetid://133212607109891" -- استبدل بالـ ID الخاص بأنيميشن التفاعل local interactionDebounce = false -- أنيميشن المشي local walkingAnimation = Instance.new("Animation") walkingAnimation.Name = "WalkingAnimation" walkingAnimation.AnimationId = WALK_ANIMATION_ID walkingAnimation.Parent = npc local walkAnimationTrack = animator:LoadAnimation(walkingAnimation) walkAnimationTrack.Looped = true walkAnimationTrack:Play() -- أنيميشن التفاعل local interactionAnimation = Instance.new("Animation") interactionAnimation.Name = "InteractionAnimation" interactionAnimation.AnimationId = INTERACTION_ANIMATION_ID interactionAnimation.Parent = npc local interactionTrack = animator:LoadAnimation(interactionAnimation) -- دالة اللمس local function onTouch(hit) if interactionDebounce then return end local character = hit.Parent if not character then return end local playerHumanoid = character:FindFirstChildOfClass("Humanoid") if playerHumanoid and Players:GetPlayerFromCharacter(character) and character ~= npc then interactionDebounce = true -- إيقاف أنيميشن المشي walkAnimationTrack:Stop() -- تشغيل أنيميشن التفاعل interactionTrack:Play() -- انتظار فترة الكول داون task.wait(INTERACTION_COOLDOWN) -- إعادة تشغيل أنيميشن المشي walkAnimationTrack:Play() interactionDebounce = false end end rootPart.Touched:Connect(onTouch) -- تنظيف عند حذف الـ NPC npc.Destroying:Connect(function() if walkAnimationTrack then walkAnimationTrack:Stop() walkAnimationTrack:Destroy() end if walkingAnimation then walkingAnimation:Destroy() end if interactionTrack then interactionTrack:Stop() interactionTrack:Destroy() end if interactionAnimation then interactionAnimation:Destroy() end end)

Okay, I understand. You've provided a Roblox Lua script for an NPC. Based on your previous request about player mechanics involving immobilization and delayed kills, I'll modify this NPC script to implement that behavior: when the NPC touches a player, it will immobilize the player and attempt to kill them after a short delay (0.8 seconds).

Here is the updated script:

Updated files
v2
اريد يلاحق لاعب ولكن يرسم مخطط لكي يذهب الي لاعب

Okay, let's modify the script to make the NPC chase the nearest player using Roblox's PathfindingService. This will allow the NPC to navigate around obstacles intelligently.

Here's the updated script incorporating pathfinding:

How it works:

  1. PathfindingService: We get the PathfindingService to calculate paths.
  2. Configuration: Added settings for detection range, path recalculation frequency, and waypoint proximity threshold.
  3. findNearestPlayer(): Scans nearby players and returns the closest living one within MAX_DETECTION_RANGE.
  4. computePath(): Uses PathfindingService:CreatePath() and path:ComputeAsync() to generate a list of waypoints from the NPC's current position to the target's position. It handles potential errors during path calculation.
  5. followPath():
    • Checks if a valid path and target exist and if the NPC isn't currently interacting.
    • Iterates through the waypoints in the currentPath.
    • Uses humanoid:MoveTo() to move the NPC towards the current waypoint.
    • Plays the walking animation while moving.
    • Checks if the NPC is close enough to the current waypoint (WAYPOINT_REACH_THRESHOLD). If so, it advances to the next waypoint.
    • Handles Enum.PathWaypointAction.Jump if the path requires jumping.
    • Stops the NPC and the animation if the path ends or is invalid.
  6. onPathBlocked(): This function is connected to the Path.Blocked event. If the path is obstructed, it clears the current path, forcing a recalculation on the next update cycle.
  7. updateMovement() (Main Loop):
    • Connected to RunService.Heartbeat for smooth, frequent updates.
    • If not interacting (interactionDebounce == false):
      • Calls findNearestPlayer() to identify a target.
      • If a target is found, it checks if a path needs to be recalculated (no current path, interval reached, or target moved significantly). If needed, it calls computePath().
      • If no target is found, it clears the current target and path.
      • Calls followPath() to execute movement along the calculated path.
    • If interacting, it stops movement and animations.
  8. onTouch() Integration:
    • Now only triggers the interaction logic if the touched part belongs to the currentTarget the NPC is actively chasing.
    • When interaction starts (interactionDebounce = true), it explicitly stops path following (currentPath = nil) and NPC movement.
    • After the cooldown, interactionDebounce becomes false, allowing the updateMovement loop to resume finding targets and pathfinding.
  9. Cleanup: The Destroying event now also disconnects the Heartbeat connection.

Now, the NPC should actively chase the nearest player, navigating around obstacles, and initiate the immobilize/kill sequence upon touching its target.*

Updated files
v3
لا اغلي انه يرسم مخطط اريد يلحق لاعب لكن اذا را جادر يحاول انه يقفز

Okay, I understand. You want the NPC to chase the player directly using Humanoid:MoveTo() without calculating a path around obstacles. If it encounters an obstacle directly in its path (like a wall), it should attempt to jump over it.

Here's the modified script implementing this direct chase and jump behavior:

Changes:

  1. Removed Pathfinding: All code related to PathfindingService, Path objects, waypoints, and computePath/followPath functions has been removed.
  2. Direct MoveTo: The updateMovement function now directly calls humanoid:MoveTo(targetPosition) if a target is found.
  3. Obstacle Raycast (checkAndJumpForObstacles):
    • This new function is called within updateMovement when the NPC is actively chasing a target.
    • It performs a short raycast (workspace:Raycast) directly in front of the NPC (rootPart.CFrame.LookVector).
    • The raycast ignores the NPC itself and its current target player.
    • If the ray hits a collidable part within the JUMP_OBSTACLE_CHECK_DISTANCE, it sets humanoid.Jump = true.
    • A JUMP_COOLDOWN (lastJumpTime) prevents the NPC from spamming jumps.
  4. Animation Control: The walking animation is played when MoveTo is active and stopped otherwise or during interaction.
  5. Interaction Logic: Remains largely the same, but now it stops the direct MoveTo command instead of path following when interactionDebounce starts.

Now, the NPC will run straight towards the nearest player. If it gets close to a wall or similar obstacle in its direct path, it will attempt to jump. It won't navigate around corners or complex structures intelligently, but it will try to clear simple barriers by jumping.*

Updated files
v4