How can I make a dummy/bot player?

I’m making a 1v1 fighting game and I wanna have a single-player mode for practicing that will use a bot as the second player, however, I don’t have much experience with this so I’m not too sure of a good way to go about it. For clarification, I’m not asking how to do AI since I know that’s a big topic and I already have an idea of how to do that, I’m just trying to figure out how I can create/spawn a bot player and have some basic control over it like killing it, respawning, changing it’s position, etc

This is my current code on the server it’s a pretty bare-bone version of what you can find on the Chickynoid github. The thought process for me was basically being able to create a real player by passing a player instance when creating the player object or creating a bot by not passing one.

local Server = {}

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

local Player = require(ServerScriptService.Modules.Player)

local playerObjects = {}

local function addConnection(userId, player)
	if playerObjects[userId] ~= nil then
		warn("Player was already connected.", userId)
		-- disconnect them
	end
	
	local playerObject = Player.new(userId, player)
	playerObjects[userId] = playerObject
	
	return playerObject
end

local function playerConnected(player)
	local playerObject = addConnection(player.UserId, player)
end

local function playerDisconnected()
	
end

function Server.initialize()
	Players.PlayerAdded:Connect(playerConnected)
	Players.PlayerRemoving:Connect(playerDisconnected)
	
	local dummyPlayerObject = addConnection(0, nil) -- Makes a dummy/bot player
end

return Server
local Player = {}
Player.__index = Player 

local ReplicatedStorage = game:GetService("ReplicatedStorage")

function Player.new(userId, player)
	local self = setmetatable({}, Player)
	
	self.player = player
	self.userId = userId
	self.dummy = not player
	self.characterType = nil -- will determine what the character/figher they're playing as
	
	if self.dummy then
		self.character = ReplicatedStorage.Assets.Models.Dummy:Clone()
		self.character.Parent = workspace
	elseif not self.dummy then
		self.character = player.Character or player.CharacterAdded:Wait()
	end

	return self
end

function Player:setCharacterType(characterType)
	self.characterType = characterType -- or getRandomCharacter() (not implemented yet)
end

return Player
1 Like

I’m a little confused on why you are posting this in the first place, it seems you have a good understanding of self (metatable) and could easily make an ai bot based off this perceived notion

how I can create/spawn a bot player and have some basic control over it like killing it, respawning, changing it’s position, etc

kill it by swinging the sword at the bot dummy?

respawn the dummy by utilizing .died on the server script that made the dummy player in the first place (sort of recursively if you understand) ->call function to set up new dummy-> have .died connection ->on died recall the function

changing position? you can use pathfinding, moveto, or just teleport pivotto() cframe.