My idea is to design a search engine in the game, where anyone could search another player’s Username, and info like DisplayName, Username, AccountAge, etc. would show up. But for it to be useful, I want it to search for info on a player that also isn’t in the game.
The interface would be looking like this:
And also the workspace sorting:
So far all I could do was to get the image, Username and the DisplayName, but for it to look like an actual thing I would also need things like AccountAge, Location the player is playing at (Country), and also access some databases that would give me important in-game stuff like CIN and Date of Enrollment.
This is the SearchMain script:
In some lines I had no idea how to, so some are in comments.
local UserService = game:GetService("UserService")
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local textBox = script.Parent.Input
local Profile = script.Parent.PROFILE
local ERROR = script.Parent.ERROR
local ERRsound = workspace.PC.FrelingMac.Screen.Error
local back = script.Parent.Back
local function onFocusLost(enterPressed, _inputObject)
if enterPressed then
-- local IDsearch = Players:GetUserIdFromNameAsync(textBox.Text)
local success, err = pcall(function()
IDsearch = Players:GetUserIdFromNameAsync(textBox.Text)
end)
if success then
local success, result = pcall(function()
return UserService:GetUserInfosByUserIdsAsync({ IDsearch })
end)
if success then
for _, userInfo in ipairs(result) do
back.Visible = true
-- local joinTime = os.time() - (userInfo.AccountAge*86400)
-- local joinDate = os.date("!*t", joinTime)
local img = Players:GetUserThumbnailAsync(userInfo["Id"], Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
--RS.TransData:FireServer(IDsearch)
Profile.Visible = true
Profile.Ime.Text = userInfo["DisplayName"] -- Name
Profile.Username.Text = userInfo["Username"] -- Username
-- Profile.Dayage.Text = tostring(userInfo.AccountAge) --Dayage
-- Profile.DOJ.Text = joinDate.day .. "/" .. joinDate.month .. "/" .. joinDate.year -- Date of join
Profile.Headshot.Image = img
end
else
ERROR.Text = "ERROR\nCan't get data"
ERROR.Visible = true
ERRsound:Play()
wait(1.5)
ERROR.Visible = false
ERROR.Text = "ERROR\nGeneral Error"
end
else
ERROR.Text = "ERROR\nUser not in Registry"
ERROR.Visible = true
ERRsound:Play()
wait(1.5)
ERROR.Visible = false
ERROR.Text = "ERROR\nGeneral Error"
end
else
textBox.Text = ""
end
end
textBox.FocusLost:Connect(onFocusLost)
back.MouseButton1Click:Connect(function ()
Profile.Visible = false
back.Visible = false
end)
An important thing to mention is that I also want the access to the database in which there are stored variables like Citizenship, and a “CIN” number.
The script in the ServerScriptService looks like this (Please forgive the written code, I know it’s horrid) :
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
local RS = game:GetService("ReplicatedStorage")
local playerData = DataStoreService:GetDataStore("PlayerData")
local Players = game:GetService("Players")
local One = math.random(0, 9)
local Two = math.random(0, 9)
local Three = math.random(0, 9)
local Four = math.random(0, 9)
local Five = math.random(0, 9)
local function onPlayerJoin(player)
local storage = Instance.new("Folder")
storage.Name = "ValueData"
storage.Parent = player
local citizenship = Instance.new("BoolValue")
citizenship.Name = "Citizenship"
citizenship.Parent = storage
local CIN = Instance.new("NumberValue")
CIN.Name = "CIN"
CIN.Parent = storage
local playerUserId = "Player_" .. player.UserId
local data = playerData:GetAsync(playerUserId)
if data then
CIN.Value = data
citizenship.Value = data
else
CIN.Value = One .. Two .. Three .. Four .. Five .. "129"
citizenship.Value = false
end
end
local function onPlayerExit(player)
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player.ValueData.Citizenship.Value)
playerData:SetAsync(playerUserId, player.ValueData.CIN.Value)
end)
if not success then
warn('Error saving data!')
end
end
And the end part that’s bugging me, basically sending data back to the SearchMain script:
local function TransferData(IDsearch)
local Username = Players:GetNameFromUserIdAsync(IDsearch)
local Info = playerData:GetAsync(Username)
if Info then
--Here it's supposed to receive the event request and send the data back to the SearchMain
end
end
The problem I’ve been having was not being able to get the data when requested, and sending it back, if anyone knows I would be delighted.
I do need some more training with databases and connecting scripts with them.
So to wrap up,
I’ve scrolled through many Documentation posts, but I’m just not sure if I’m doing it right.
Also, do I need to use HttpService with this? Because web scripting is just something I have no idea about, same with APIs. If anyone has any ideas, suggestions or anything be free to reply.