✓ Accepted answer
First off, you need to make your database secure. It's very easy for hackers to get your API web address even if it's in a private module. Make sure people can't edit your database from your URL. Back to LUA though.
You have to create a TextLabel on the client. This can be done many ways but the method I'm about to show you is a little hacky and I suggest you read up about RemoteEvents.
local Players= game:GetService("Players")
local HttpService = game:GetService("HttpService")
local function playerAdded(player)
local data = HttpService:GetAsync("https://./api.php/users/1?columns=name", true)
local luaData = HttpService:JSONDecode(data)
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "databaseRank"
screenGui.ResetOnSpawn = false
local rankTag = Instance.new("TextLabel")
rankTag.Parent = screenGui
rankTag.BackgroundColor3 = Color3.new(1, 1, 1)
rankTag.BorderColor3 = Color3.new(1, 1, 1)
rankTag.BorderSizePixel = 0
rankTag.Position = UDim2.new(0, 10, 0, 10)
rankTag.Size = UDim2.new(0, 200, 0, 50)
rankTag.Font = Enum.Font.SourceSans
rankTag.TextColor3 = Color3.new(0, 0, 0)
rankTag.TextSize = 25
rankTag.Text = luaData["name"]
screenGui.Parent = player:WaitForChild("PlayerGui")
end
Players.PlayerAdded:Connect(playerAdded)
Ideally this would be run on the client side but for debug purposes, this works.
You should find out how RemoteEvents can be used to invoke the client and generate the GUI on the user's machine rather than on the server.
Also, don't just copy and paste my code, read the comments I put it, they are important if you want to improve as a programmer.
1 comment
Just a side note. I am planning on doing a system where it sends a request based on the players name. So I WILL be needing to use this however for now I will just be testing so in other words please don't just send me messages saying I don't need to use Http Service..