where do i put the script?
- User
where do i put the script?
Assistant
You need to put the script inside your Noobster NPC model. Here's exactly how to do it:
Step-by-Step Instructions:
1. Locate Your Noobster NPC
- In Roblox Studio, look in the Workspace or wherever you have your Noobster NPC model
2. Add a Server Script
- Right-click on your Noobster model (not a part inside it, but the actual model)
- Select "Insert Object"
- Choose "Script" (NOT LocalScript or ModuleScript)
3. Configure the Script
- The new script will appear inside your Noobster model
- Double-click the script to open it
- Delete any default code (like
print("Hello world!")) - Paste the pathfinding code I provided
4. Verify Your Setup
Your hierarchy should look like this:
Workspace └── Noobster (Model) ├── HumanoidRootPart (Part) ├── Head (Part) ├── Torso (Part) ├── Left Arm (Part) ├── Right Arm (Part) ├── Left Leg (Part) ├── Right Leg (Part) ├── Humanoid └── Script ← Your pathfinding script goes here5. Make Sure Your NPC is Set Up Correctly
- Select your Noobster model
- In the Properties window, set the PrimaryPart to HumanoidRootPart
- Make sure the Humanoid is present in the model
6. Test It
- Click the Play button in Studio
- Join as a player and walk around
- Noobster should start following you when you get within 200 studs
Important Notes:
- Use a Server Script, not a LocalScript (LocalScripts won't work for controlling NPCs)
- The script must be inside the NPC model because it uses
script.Parentto reference the NPC - Make sure your NPC has all the standard R15 or R6 body parts and a Humanoid
If you're still having trouble, you can also:
- Right-click in the Workspace
- Insert → Model
- Name it "Noobster"
- Insert the body parts and Humanoid manually
- Then add the script
Let me know if you need help with any of these steps!
- User
ok the npc almost like lags foword so make it more smooth. and try to make it so when noobster have a clear view of the player it goes in to sprint mode and uses its sprinting animation, and make it so if the noobster touches a player he does 50 damage, so you die if you touch him 2 times
Assistant
Here's the improved script with smooth movement, sprint mode, and damage on touch:
local npc = script.Parent local humanoid = npc:FindFirstChild("Humanoid") local rootPart = npc:FindFirstChild("HumanoidRootPart") or npc.PrimaryPart -- Services local PathfindingService = game:GetService("PathfindingService") local Players = game:GetService("Players") local RunService = game:GetService("RunService") local TweenService = game:GetService("TweenService") -- Configuration local DETECTION_RANGE = 200 -- How far away Noobster can detect players local WALK_SPEED = 8 -- Normal walking speed local SPRINT_SPEED = 22 -- Sprint speed when having clear line of sight local RECALCULATE_TIME = 0.5 -- How often to recalculate path (faster for smoother movement) local WAYPOINT_DISTANCE = 2 -- How close to waypoint to consider it reached local DAMAGE_AMOUNT = 50 -- Damage dealt per touch local DAMAGE_COOLDOWN = 1 -- Seconds between damage instances per player -- State tracking local isPathfinding = false local isSprintMode = false local currentPath = nil local currentWaypointIndex = 0 local lastPathfindTime = 0 local targetPlayer = nil local damageCooldowns = {} -- Track damage cooldowns per player -- Make sure NPC has required components if not humanoid then error("Noobster must have a Humanoid") return end if not rootPart then error("Noobster must have a HumanoidRootPart or PrimaryPart") return end -- Set network ownership for smoother physics pcall(function() rootPart:SetNetworkOwner(nil) end) -- Create animations with default Roblox IDs local walkAnimation = Instance.new("Animation") walkAnimation.AnimationId = "rbxassetid://913402848" -- Default walk local sprintAnimation = Instance.new("Animation") sprintAnimation.AnimationId = "rbxassetid://913376220" -- Default run/sprint -- Load animations local walkTrack = humanoid:LoadAnimation(walkAnimation) local sprintTrack = humanoid:LoadAnimation(sprintAnimation) -- Set up damage system local function setupDamageDetection() -- Get all parts of the NPC that can deal damage local damageParts = {} for _, part in pairs(npc:GetChildren()) do if part:IsA("BasePart") and part ~= rootPart then table.insert(damageParts, part) end end -- Connect touch events to all parts for _, part in pairs(damageParts) do part.Touched:Connect(function(hit) local character = hit.Parent local hitHumanoid = character:FindFirstChild("Humanoid") local player = Players:GetPlayerFromCharacter(character) -- Check if we hit a player if player and hitHumanoid and hitHumanoid.Health > 0 then local playerId = player.UserId local currentTime = tick() -- Check cooldown if not damageCooldowns[playerId] or currentTime - damageCooldowns[playerId] >= DAMAGE_COOLDOWN then -- Deal damage hitHumanoid.Health = math.max(0, hitHumanoid.Health - DAMAGE_AMOUNT) damageCooldowns[playerId] = currentTime -- Visual effect (optional) local damageEffect = Instance.new("Explosion") damageEffect.Size = 5 damageEffect.BlastRadius = 0 damageEffect.BlastPressure = 0 damageEffect.Position = hit.Position damageEffect.Parent = workspace print("Noobster dealt " .. DAMAGE_AMOUNT .. " damage to " .. player.Name) if hitHumanoid.Health <= 0 then print(player.Name .. " was eliminated by Noobster!") end end end end) end end -- Function to check if there's a clear line of sight to target local function hasLineOfSight(target) if not target or not target:FindFirstChild("HumanoidRootPart") then return false end local rayParams = RaycastParams.new() rayParams.FilterDescendantsInstances = {npc} rayParams.FilterType = Enum.RaycastFilterType.Blacklist local direction = (target.HumanoidRootPart.Position - rootPart.Position) local result = workspace:Raycast(rootPart.Position, direction, rayParams) -- Clear line of sight if nothing was hit or we hit the target return not result or result.Instance:IsDescendantOf(target) end -- Function to find the nearest player local function findNearestPlayer() local nearestPlayer = nil local nearestDistance = DETECTION_RANGE for _, player in pairs(Players:GetPlayers()) do local character = player.Character if character and character:FindFirstChild("HumanoidRootPart") and character:FindFirstChild("Humanoid") then if character.Humanoid.Health > 0 then local distance = (rootPart.Position - character.HumanoidRootPart.Position).Magnitude if distance < nearestDistance then nearestPlayer = character nearestDistance = distance end end end end return nearestPlayer, nearestDistance end -- Function to update movement mode based on line of sight local function updateMovementMode(target) local hasLOS = hasLineOfSight(target) if hasLOS and not isSprintMode then -- Switch to sprint mode isSprintMode = true walkTrack:Stop() sprintTrack:Play() humanoid.WalkSpeed = SPRINT_SPEED print("Noobster is sprinting - clear line of sight!") elseif not hasLOS and isSprintMode then -- Switch back to walk mode isSprintMode = false sprintTrack:Stop() walkTrack:Play() humanoid.WalkSpeed = WALK_SPEED print("Noobster is walking - no clear line of sight") end end -- Function to create a path to the target local function createPathToTarget(targetPosition) if not targetPosition then return nil end local path = PathfindingService:CreatePath({ AgentRadius = 2, AgentHeight = 5, AgentCanJump = true, AgentCanClimb = false, WaypointSpacing = 4, -- Closer waypoints for smoother movement Costs = { Water = 20 -- Avoid water if possible } }) local success, errorMessage = pcall(function() path:ComputeAsync(rootPart.Position, targetPosition) end) if success and path.Status == Enum.PathStatus.Success then return path else return nil end end -- Function to follow a path smoothly local function followPath(path) if not path then return end local waypoints = path:GetWaypoints() if #waypoints <= 1 then return end isPathfinding = true currentPath = path currentWaypointIndex = 2 -- Skip starting position -- Start with walking animation if not isSprintMode then sprintTrack:Stop() walkTrack:Play() humanoid.WalkSpeed = WALK_SPEED end end -- Function to stop pathfinding local function stopPathfinding() isPathfinding = false isSprintMode = false currentPath = nil walkTrack:Stop() sprintTrack:Stop() humanoid:MoveTo(rootPart.Position) end -- Smooth pathfinding update function local function updatePathfinding() if not isPathfinding or not currentPath then return end local waypoints = currentPath:GetWaypoints() if currentWaypointIndex > #waypoints then stopPathfinding() return end local currentWaypoint = waypoints[currentWaypointIndex] -- Handle jumping if currentWaypoint.Action == Enum.PathWaypointAction.Jump then humanoid.Jump = true end -- Move towards waypoint humanoid:MoveTo(currentWaypoint.Position) -- Check if reached waypoint local distance = (rootPart.Position - currentWaypoint.Position).Magnitude if distance <= WAYPOINT_DISTANCE then currentWaypointIndex = currentWaypointIndex + 1 end end -- Main game loop with higher frequency updates local updateConnection updateConnection = RunService.Heartbeat:Connect(function(deltaTime) -- Check if NPC still exists if not npc.Parent or humanoid.Health <= 0 then updateConnection:Disconnect() return end -- Find the nearest player local nearestPlayer, distance = findNearestPlayer() if nearestPlayer then targetPlayer = nearestPlayer -- Update movement mode based on line of sight updateMovementMode(nearestPlayer) -- Check if we need to recalculate path local now = tick() if not isPathfinding or (now - lastPathfindTime > RECALCULATE_TIME) then lastPathfindTime = now local targetPosition = nearestPlayer.HumanoidRootPart.Position local path = createPathToTarget(targetPosition) if path then followPath(path) end end -- Update current pathfinding updatePathfinding() else -- No player in range if isPathfinding then stopPathfinding() end targetPlayer = nil end end) -- Initialize damage system setupDamageDetection() -- Optional: Create a glowing effect when in sprint mode task.spawn(function() while true do if isSprintMode and npc.Parent then -- Add a slight red glow effect when sprinting for _, part in pairs(npc:GetChildren()) do if part:IsA("BasePart") then local currentColor = part.Color part.Color = Color3.new(math.min(1, currentColor.R + 0.2), currentColor.G * 0.8, currentColor.B * 0.8) task.wait(0.1) part.Color = currentColor end end end task.wait(0.2) end end) print("Noobster is ready to hunt! 🔥")Key Improvements:
🎯 Smoother Movement
- Faster Updates: Uses
RunService.Heartbeatfor 60fps updates - Closer Waypoints:
WaypointSpacing = 4creates more waypoints for smoother paths - Better Pathfinding: Optimized agent parameters and path recalculation timing
🏃 Sprint Mode
- Line of Sight Detection: Uses raycasting to detect clear view of player
- Dynamic Speed: Switches between 8 (walk) and 22 (sprint) speed
- Visual Feedback: Slight red glow effect when sprinting
- Animation Switching: Smoothly transitions between walk and sprint animations
⚔️ Damage System
- Touch Damage: Deals 50 damage on contact (2 hits = death)
- Cooldown System: 1-second cooldown per player to prevent spam damage
- Visual Effects: Small explosion effect on damage
- Death Detection: Announces when a player is eliminated
🛡️ Additional Features
- Smart Pathfinding: Avoids water and obstacles better
- Error Handling: Robust error checking and cleanup
- Performance: Efficient update loops and memory management
- Debug Info: Console messages for tracking behavior
How It Works:
- Detection: Noobster scans for players within 200 studs
- Line of Sight: If he can see you directly → SPRINT MODE 🏃♂️
- Obstacles: If view is blocked → normal walking speed 🚶♂️
- Contact: Touch Noobster = 50 damage + explosion effect 💥
- Smooth Pursuit: Updates path every 0.5 seconds for fluid movement
The movement should now be much smoother and more threatening when Noobster has a clear view of you!
- Faster Updates: Uses
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.