@FMDGunawardena

How do u creat games can someoene tell me i might make one and make it good

@r6rig

Lmao this is literally just a regular ai with a killbrick script in its torso

@Xxx_wiwi_xxX-v6s

Ai idea: its better and epic if make him Chase you making strategys moves

@BananaRobloxStudio

This Is The Script (Put Inside A Rig) local AI = script.Parent -- gets the ai
local humanoid = AI.Humanoid -- gets the ai's humanoid
local PathfindingService = game:GetService("PathfindingService") -- gets the pathFindingService
AI.PrimaryPart:SetNetworkOwner(nil) -- sets it so the client cannot move the ai, usefull for anti exploits and glitches

local function canSeeTarget(target)
	local origin = AI.HumanoidRootPart.Position -- gets the ai's position
	local direction = (target.HumanoidRootPart.Position - AI.HumanoidRootPart.Position).unit * 40 -- gets the direction to the target
	local ray = Ray.new(origin, direction) -- creates a ray

	local hit, pos = workspace:FindPartOnRay(ray, AI) -- does a raycast, the ai is ignored

	if hit then -- if the ray hit anything
		if hit:IsDescendantOf(target) then -- checks if the thing the ray hit is a descendant of the target(the target is a character)
			return true -- returns true to the thing that called the function
		end
	else -- if the thing the ray hit is just a normal object and is not a descendent of the player's character
		return false -- returns false to the thing that called the function
	end
end





local function findTarget() -- finds the target
	local players = game.Players:GetPlayers() -- gets the players
	local maxDistance = 40 -- maxdistance in studs
	local nearestTarget -- nearest target, starts at nil

	for index, player in pairs(players) do -- gets all players in the players table
		if player.Character then -- if player has character
			local target = player.Character -- sets the target to the players character
			if target and target:FindFirstChild("HumanoidRootPart") then -- if the target exists
				local distance = (AI.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude -- finds the distance between the ai and the player
				if distance < maxDistance and canSeeTarget(target) then -- if the distance is less than the maxdistance then
					nearestTarget = target -- sets a new nearest target
					maxDistance = distance -- sets a new nearest distance
				end
			end
		end
	end
	return nearestTarget -- returns the nearest target to this thing that called the function
end

local function getPath(destination) 
	local pathParams = {  -- parameters
		["AgentHeight"] = 5, -- character height(dont change)
		["AgentRadius"] = 2.5, -- character diameter(dont change)
		["AgentCanJump"] = true -- sets so that the character can or cannot jump		
	}
	local path = PathfindingService:CreatePath(pathParams) -- creates a path with the parameters

	path:ComputeAsync(AI.HumanoidRootPart.Position, destination.Position) -- computes the best way to complete that path

	if path.Status == Enum.PathStatus.Success then

		return path -- returns path

	else
		local Newpath = PathfindingService:CreatePath(pathParams) -- makes a new path
		Newpath:ComputeAsync(AI.HumanoidRootPart.Position, destination.Position) -- makes a new path
		print("no path :(")
		humanoid:MoveTo(destination.Position - (AI.HumanoidRootPart.CFrame.LookVector * 10))
		return Newpath -- returns the newPath


	end

end

local function attack(target) -- attacks a target
	local distance = (AI.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude -- finds the distance between the ai and the player

	if distance > 2 then -- if its close enough to attack
		humanoid:MoveTo(target.HumanoidRootPart.Position) -- moves to the players character
	else -- if the players character is close enough to kill
		target.Humanoid.Health = 0 -- kills the player
	end
end

local function walkTo(destination) -- walks to the destination


	local path = getPath(destination) -- the function returns the path



	if path.Status == Enum.PathStatus.Success then -- if success
		for index, waypoint in pairs(path:GetWaypoints()) do -- gets all the waypoints for that path

			local target = findTarget() -- calls the find target
			if target and target.Humanoid.Health > 0 then -- checks if there is a target and the target is alive 

				attack(target) -- attacks the target
				break -- breaks the for loop

			else -- if no target or the player is dead
				if waypoint.Action == Enum.PathWaypointAction.Jump then -- if it has to jump
					humanoid:ChangeState(Enum.HumanoidStateType.Jumping) -- jumps
				end



				print("Moving to", waypoint.Position) -- prints where it is moving to

				humanoid:MoveTo(waypoint.Position) -- moves to
				humanoid.MoveToFinished:Wait() -- waits


			end

		end
	else -- if no success

		humanoid:MoveTo(destination.Position - (AI.HumanoidRootPart.CFrame.LookVector * 10)) -- moves back 10 studs

		humanoid.MoveToFinished:Wait() -- waits
	end
end






local function patrol() 


	local waypoints = workspace.Waypoints:GetChildren() -- gets all waypoints
	local randomNum = math.random(1, #waypoints) -- gets a random number between 1 and the total waypoints





	walkTo(waypoints[randomNum]) -- walks to the random waypoint



end


while task.wait() do -- every frame

	patrol() -- patrols
end

humanoid.MoveToFinished:Connect(function()
	print("finished")
end)

@Ahmed7amodTarek

Yo I wanna start making game on Roblox but where do I learn?

@mango-e6k

Now make it follow you when your behind a wall.

@AirmanGT

Bro i want the code so i can make horror games

@BIASXED

Ts is just normal pathfinding with a kill script :/

@TenebRom

Ai killer?pfff, is a simple bot.