← Back to All Parts
🐍
Part 412 min

Mini-Project 1 - Chase Game (Basilisk Practice!)

Now we'll make something chase the player - just like the Basilisk will in your final game! This is one of the most important skills you'll need.

Step 1: Create the Chaser

Step 1: Create the Chaser
Screenshot: Step 1: Create the Chaser

Step 2: Add the Chase Script

Right-click Chaser → Insert Object → Script. Then add this code:

-- Simple Chase Script
local chaser = script.Parent
local chaseSpeed = 10

while true do
    -- Find the closest player
    local closestPlayer = nil
    local closestDistance = math.huge

    for _, player in pairs(game.Players:GetPlayers()) do
        if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
            local playerPosition = player.Character.HumanoidRootPart.Position
            local distance = (chaser.Position - playerPosition).Magnitude

            if distance < closestDistance then
                closestDistance = distance
                closestPlayer = player
            end
        end
    end

    -- Move toward the closest player
    if closestPlayer then
        local playerPos = closestPlayer.Character.HumanoidRootPart.Position
        local direction = (playerPos - chaser.Position).Unit
        chaser.Velocity = direction * chaseSpeed
    end

    -- Check if we caught someone!
    if closestDistance < 5 then
        print("CAUGHT " .. closestPlayer.Name .. "!")
    end

    wait(0.1)
end

What's Happening Here?

while true do
The loop runs forever
Magnitude
Measures distance between two things
Unit
Gives us which direction to go
Velocity
Makes the part move!

Test Your Chase Game!

Make It Harder!

Try changing "local chaseSpeed = 10" to a bigger number like 15 or 20. Can you still escape?

✅ Checklist - Check them off!

You made enemy AI! The green block hunts you down!