ROBLOX ARTIFICIAL INTELLIGENCE [CHAT BOT]
Hello, recently I’ve been working on a NPC Artificial Intelligence Chatting system.
This means that this system/ feature uses actual artificial intelligence and neural networking, which makes the A.I Make it’s own decisions when talking to a user.
This Artificial Intelligence feature will bring a whole new experience through players in game and actual NPC:s.
I’ll be walking you through on how you can get this feature/system on your game.
Do not worry I’ll be explaining everything step-by-step.
At the end you will be able to see the fully working end result.
You can test this feature on this Game Note, It’s group locked only Group Members can test it out.
Update Log!
Please NOTE: Updates can be tested on the Testing game Provided on this post.
-
-
[V 1 Updates]
● [NEW] Added Naming Feature - Allows you to name your A.I This Can be passed when making the api request.
● [UPDATED] API route updated - Luiboard AI is now moved Here and nolonger Here (Moved^)
● [UPDATED] Getting your Apikey - You can now get your api key via your profile settings! and is no longer here
-
[V 1 Updates]
How does this feature work?
-
This feature uses roblox HttpService which means that uses will need to have https service on their games if they’re considering using this feature.
-
Once your have the https service enabled. You will need to send an api request to Luiboard AI Api. This request will be sent here.
-
Before trying to send any api request you do need to have an api key which can be obtained by going to your profile.
-
Note: You need to log in on the site to obtain your api key. The site uses Discord OAuth2 to log you in.
-
Once you have your api key you’re all set to get started
What is Luiboard?
- Luiboard is a website I developed to help and offer roblox developers open source resources from scripting system to models [WIP]
SET UP
- Now assuming you’ve read though the top section of this post and you have your api key I’ll show you have you can test this feature our or even potentially add it to your game.
Let’s start with setting up this feature for testing.
Workspace
- Create a folder and name it NPCS
- In that folder add a character model of your choice
Example: https://gyazo.com/38db950d43e2eadf48303d255bea10c1
ServerScriptService
- On here add a server script and continue write down the code below
--We will start with getting HTTPService
--// Services
local Players = game:GetService("Players")
local SS = game:GetService("ServerStorage")
local Chat = game:GetService("Chat")
--// Imports
--Create a module script in ServerStorage and call it "CoreModule"
-- We will script this module script later on this post.
local CoreModule = require(SS["CoreModule"])
--// Components
-- Here we are getting the npc:s from the workspace
local NPCS = workspace["NPCS"]:GetChildren()
--//Settings
-- Right here we are enabling the beautiful Bubble Chat :)
Chat.BubbleChatEnabled = true
--// Handler
-- Detecting whenever a player joins
Players.PlayerAdded:Connect(function(Player)
-- Detecting whether a player chats
Player.Chatted:Connect(function(Message)
CoreModule.FetchRespnose(Message:match("[%P]+"),Player.UserId) -- Calling the function we made on the CoreModule
local Response = Chat:FilterStringForBroadcast(_G.Res, Player)
wait(1)
Chat:Chat(NPCS[1]["Head"],Response)v -- Getting the first NPC:s head on our NPC folder on the workspace and then passing the response where by the NPC will display.
end)
end)
ServerStorage
-
On the server storage add a module script and name it “CoreModule”
-
Once done let’s get back into coding!
--//Services
local SS = game:GetService("ServerStorage")
local TS = game:GetService("TextService")
local CoreModule = {}
_G.Res = " " -- This is going to be our global response
local HttpService = game:GetService("HttpService") -- We now get to use HTTPService
--// Functions
function CoreModule.FetchRespnose(q,Id) -- This function is going to fetch our response from the luibaord ai api.
local Request
local Success, Err = pcall(function() -- We wrap the request fuction in a pcall to avoid getting any errors if something goes wrong.
Request = HttpService:RequestAsync(
{
Url = "https://api.luiboard.com/ai/v1/fetch?message="..tostring(q), -- This is the url we are requesting too!
Method = "GET",
Headers = {
["Content-Type"] = "application/json",
["apikey"] = "Your api key you got from Luiboard.com", --You can get it by going to your profile on the Luiboard website.
["id"] = tostring(Id)
},
}
)
end)
if not(Success)then
_G.Res = "Huh?" -- If the request fails we return this string as a response, you can also print out the error right here.
else
local Pattern,PatternTable = "\\([ntr])",{n = "\n", t ="\t", r = " "} -- This is a regex Pattern I made to get rid of all the ASCII Charcters
local Pattern2 = "([\"])" -- Right here we get rid of the quotations
local FetchedResponse = HttpService:JSONDecode(Request.Body) -- Here we turn the JsonData into a Lua Table
local Response = string.gsub(FetchedResponse.Response:gsub(Pattern, PatternTable),"[\"\\]","")
local FilteredResponse = ""
local success, err = pcall(function()
FilteredResponse = TS:FilterStringAsync(Response, Id) -- Right here we filter the text before seding it to the user
end)
if not success then
_G.Res = "Sorry I did not catch what you said."
else
_G.Res = Response -- We return the response.
end
end
end
return CoreModule
If you encounter any Issues or need help Mention Me
The clip below displays the end result.
Extended Video Link
If you encounter any Issues or need help Mention Me
You can test this feature on this Game Note, It’s group locked only Group Members can test it out.
- Feel Free to use this on your NPC’s Sytems.
UNCOPY LOCKED PLACE You will only need your api key.
TESTING PLACE - This place is group locked. But a great place to test it out. It has multiple NPC’s That use this feature.