0% found this document useful (0 votes)
11 views6 pages

Text 14

The document is a Lua script for a Roblox game that implements a real-time chat system using an external API. It creates a user interface for message input and displays messages from users, while managing user commands for muting and sending messages. The script includes functions for fetching assets, polling messages, and handling user input to enhance the chat experience.

Uploaded by

devatdev664
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Text 14

The document is a Lua script for a Roblox game that implements a real-time chat system using an external API. It creates a user interface for message input and displays messages from users, while managing user commands for muting and sending messages. The script includes functions for fetching assets, polling messages, and handling user input to enhance the chat experience.

Uploaded by

devatdev664
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

local plyrs = game:GetService("Players")

local httpsrv = game:GetService("HttpService")


local inputsrv = game:GetService("UserInputService")
local twsrv = game:GetService("TweenService")
local assetsrv = game:GetService("AssetService")
local runsrv = game:GetService("RunService")
local gui = game:GetService("CoreGui")
local url = "https://api.piesocket.com/v1/channel/ix7/messages"
local key = "demo"
local ply = plyrs.LocalPlayer
local msgs = {}
local txt = ""
local vis = false
local last = 0
local sent = {}
local mute = {}
local warn = 0
local lock = 0
local cache = {}
local queue = {}
local base = "https://assetdelivery.roblox.com/v1/assetId/"

local scr = Instance.new("ScreenGui")


scr.IgnoreGuiInset = true
scr.Parent = gethui and gethui() or gui

local frm = Instance.new("Frame")


frm.Size = UDim2.new(0.28, 0, 0.42, 0)
frm.Position = UDim2.new(0.01, 0, 0.01, 0)
frm.BackgroundColor3 = Color3.fromRGB(4, 4, 6)
frm.BackgroundTransparency = 0.25
frm.BorderSizePixel = 0
frm.Parent = scr

local crn = Instance.new("UICorner")


crn.CornerRadius = UDim.new(0.12, 0)
crn.Parent = frm

local aura = Instance.new("UIGradient")


aura.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(130, 130, 255)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(30, 30, 160))
})
aura.Rotation = 75
aura.Parent = frm

local edge = Instance.new("UIStroke")


edge.Color = Color3.fromRGB(100, 100, 230)
edge.Thickness = 1.2
edge.Transparency = 0.4
edge.Parent = frm

local ttl = Instance.new("TextLabel")


ttl.Size = UDim2.new(0.94, 0, 0.07, 0)
ttl.Position = UDim2.new(0.03, 0, 0.02, 0)
ttl.BackgroundTransparency = 1
ttl.Text = "IX7 RTC"
ttl.TextColor3 = Color3.fromRGB(235, 235, 255)
ttl.TextSize = 24
ttl.Font = Enum.Font.AmaticSC
ttl.TextXAlignment = Enum.TextXAlignment.Left
ttl.TextStrokeTransparency = 0.6
ttl.TextStrokeColor3 = Color3.fromRGB(20, 20, 60)
ttl.Parent = frm

local lst = Instance.new("UIListLayout")


lst.SortOrder = Enum.SortOrder.LayoutOrder
lst.Padding = UDim.new(0, 2)
lst.Parent = frm

local inp = Instance.new("TextBox")


inp.Size = UDim2.new(0.93, 0, 0.06, 0)
inp.Position = UDim2.new(0.035, 0, 0.92, 0)
inp.BackgroundColor3 = Color3.fromRGB(12, 12, 18)
inp.TextColor3 = Color3.fromRGB(245, 245, 245)
inp.Text = ""
inp.PlaceholderText = "Talk..."
inp.TextSize = 13
inp.Font = Enum.Font.GothamSemibold
inp.BorderSizePixel = 0
inp.Visible = false
inp.Parent = frm

local incrn = Instance.new("UICorner")


incrn.CornerRadius = UDim.new(0.4, 0)
incrn.Parent = inp

local instr = Instance.new("UIStroke")


instr.Color = Color3.fromRGB(100, 100, 230)
instr.Thickness = 0.7
instr.Transparency = 0.5
instr.Parent = inp

local function probe(id)


if cache[id] then return cache[id] end
local ok, res = pcall(function()
return httpsrv:RequestAsync({
Url = base .. id,
Method = "GET"
})
end)
if ok and res.Success then
local d = httpsrv:JSONDecode(res.Body)
if d and d.locations and d.locations[1] and d.locations[1].location then
cache[id] = d.locations[1].location
return cache[id]
end
end
return nil
end

local function fetch(id)


local url = probe(id)
if not url then return nil end
local ok, res = pcall(function()
return assetsrv:GetAssetById(id)
end)
if ok and res then return res end
local alt = 0
while alt < 20 do
local newid = id + alt
url = probe(newid)
if url then
ok, res = pcall(function()
return assetsrv:GetAssetById(newid)
end)
if ok and res then
cache[id] = url
return res
end
end
alt = alt + 1
task.wait(0.05)
end
return nil
end

local function hook()


local mt = getrawmetatable(game)
local old = mt.__index
setrawmetatable(game, {
__index = function(t, k)
if k == "MeshContextProvider" then
return function(...)
local args = {...}
if args[1] and type(args[1]) == "number" then
local res = fetch(args[1])
if res then return res end
end
return nil
end
end
return old(t, k)
end
})
end

local function sync()


while task.wait(0.5) do
for id, _ in queue do
if not cache[id] then
task.spawn(function()
fetch(id)
end)
end
end
end
end

local function addmsg(snd, txt)


if mute[snd] or (snd ~= "sys" and mute.all) then return end
local lbl = Instance.new("TextLabel")
lbl.Size = UDim2.new(0.93, 0, 0, 16)
lbl.Position = UDim2.new(0.035, 0, 0, 0)
lbl.BackgroundTransparency = 1
lbl.TextColor3 = Color3.fromRGB(235, 235, 235)
lbl.Text = snd .. ": " .. txt
lbl.TextSize = 12
lbl.Font = Enum.Font.Gotham
lbl.TextXAlignment = Enum.TextXAlignment.Left
lbl.TextWrapped = true
lbl.TextTransparency = 1
lbl.Parent = frm
twsrv:Create(lbl, TweenInfo.new(0.15, Enum.EasingStyle.Cubic),
{TextTransparency = 0}):Play()
msgs[#msgs + 1] = lbl
if #msgs > 10 then
local old = msgs[1]
twsrv:Create(old, TweenInfo.new(0.15, Enum.EasingStyle.Cubic),
{TextTransparency = 1}):Play()
task.wait(0.15)
old:Destroy()
table.remove(msgs, 1)
end
end

local function poll()


local ok, res = pcall(function()
return httpsrv:RequestAsync({
Url = url .. "?api_key=" .. key,
Method = "GET"
})
end)
if ok and res.Success then
local d = httpsrv:JSONDecode(res.Body)
if d and d.messages then
for _, m in d.messages do
if m.sender and m.msg then
addmsg(m.sender, m.msg)
end
end
end
end
task.spawn(function()
task.wait(0.4)
poll()
end)
end

local function spam()


local now = tick()
for i = #sent, 1, -1 do
if now - sent[i] > 4 then
table.remove(sent, i)
end
end
if #sent >= 3 then
warn = warn + 1
addmsg("sys", "warn " .. warn .. "/3: ease up")
if warn >= 3 then
lock = now + 25
warn = 0
addmsg("sys", "locked 25s")
end
return false
end
return true
end

local function parse(txt)


if txt:sub(1, 1) ~= "/" then return nil end
local args = {}
for w in txt:gmatch("%S+") do
args[#args + 1] = w
end
return args[1]:sub(2):lower(), args
end

local function send(msg)


if tick() <= lock then
addmsg("sys", "locked " .. math.ceil(lock - tick()) .. "s")
return
end
if tick() - last < 0.4 or not spam() then return end
local ok = pcall(function()
httpsrv:RequestAsync({
Url = url,
Method = "POST",
Headers = {
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. key
},
Body = httpsrv:JSONEncode({sender = ply.Name, msg = msg})
})
end)
if ok then
sent[#sent + 1] = tick()
last = tick()
end
end

inputsrv.InputBegan:Connect(function(key, gp)
if gp then return end
if key.KeyCode == Enum.KeyCode.T and not vis then
vis = true
inp.Visible = true
inp:CaptureFocus()
txt = ""
inp.Text = ""
twsrv:Create(inp, TweenInfo.new(0.15, Enum.EasingStyle.Cubic),
{BackgroundTransparency = 0, TextTransparency = 0}):Play()
elseif key.KeyCode == Enum.KeyCode.Return and vis then
if txt ~= "" then
local c, args = parse(txt)
if c == "mute" and args[2] then
mute[args[2]] = true
addmsg("sys", "muted " .. args[2])
elseif c == "unmute" and args[2] then
mute[args[2]] = nil
addmsg("sys", "unmuted " .. args[2])
elseif c == "muteall" then
mute.all = true
addmsg("sys", "muted all")
elseif c == "unmuteall" then
mute.all = nil
addmsg("sys", "unmuted all")
else
send(txt)
end
end
vis = false
twsrv:Create(inp, TweenInfo.new(0.15, Enum.EasingStyle.Cubic),
{BackgroundTransparency = 1, TextTransparency = 1}):Play()
task.wait(0.15)
inp.Visible = false
inp:ReleaseFocus()
end
end)

inp:GetPropertyChangedSignal("Text"):Connect(function()
if vis then
txt = inp.Text
end
end)

task.spawn(function()
hook()
sync()
poll()
end)

if loader() then
task.spawn(function()
local res = fetch(9453023)
if res then
addmsg("sys", "asset 9453023 loaded")
end
poll()
end)
end

You might also like