
KeylessUniversal

-- ============================================
-- ROBLOX P2P SYNC REAL (CHAT ANTIGO + EVENTOS)
-- Sala fixa: room_1771375142143_egez7i58n
-- ============================================
local ROOM_ID = "room_1771375142143_egez7i58n"
local SERVER_URL = "https://preview-sandbox--fc671c8f1b2aaed12b176e9b14797ff5.base44.app"
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local player = Players.LocalPlayer
local CLIENT_ID = HttpService:GenerateGUID(false)
local lastChatId = ""
local lastEventId = ""
print("===================================")
print("SYNC REAL ATIVO")
print("Sala:", ROOM_ID)
print("Player:", player.Name)
print("Client ID:", CLIENT_ID)
print("===================================")
------------------------------------------------
-- ENVIAR CHAT (CHAT PADRÃO ROBLOX)
------------------------------------------------
player.Chatted:Connect(function(msg)
pcall(function()
HttpService:RequestAsync({
Url = SERVER_URL .. "/api/chat/send",
Method = "POST",
Headers = {["Content-Type"] = "application/json"},
Body = HttpService:JSONEncode({
room_id = ROOM_ID,
client_id = CLIENT_ID,
sender = player.Name,
message = msg,
time = os.time()
})
})
end)
end)
------------------------------------------------
-- RECEBER CHAT (MOSTRA BOLHA NORMAL)
------------------------------------------------
local function pollChat()
local ok, res = pcall(function()
return HttpService:RequestAsync({
Url = SERVER_URL .. "/api/chat/messages?room_id=" .. ROOM_ID .. "&after=" .. lastChatId,
Method = "GET"
})
end)
if ok and res.Success then
local data = HttpService:JSONDecode(res.Body)
for _, msg in ipairs(data.messages or {}) do
if msg.client_id ~= CLIENT_ID then
local target = Players:FindFirstChild(msg.sender)
if target and target.Character and target.Character:FindFirstChild("Head") then
Chat:Chat(target.Character.Head, msg.message, Enum.ChatColor.White)
end
end
lastChatId = msg.id or lastChatId
end
end
end
------------------------------------------------
-- ENVIAR EVENTOS VISUAIS
------------------------------------------------
local function sendEvent(eventType, data)
pcall(function()
HttpService:RequestAsync({
Url = SERVER_URL .. "/api/events/smart",
Method = "POST",
Headers = {["Content-Type"] = "application/json"},
Body = HttpService:JSONEncode({
room_id = ROOM_ID,
client_id = CLIENT_ID,
event_type = eventType,
event_data = data,
time = os.time()
})
})
end)
end
------------------------------------------------
-- RECEBER EVENTOS VISUAIS
------------------------------------------------
local function pollEvents()
local ok, res = pcall(function()
return HttpService:RequestAsync({
Url = SERVER_URL .. "/api/events/smart?room_id=" .. ROOM_ID .. "&after=" .. lastEventId,
Method = "GET"
})
end)
if ok and res.Success then
local data = HttpService:JSONDecode(res.Body)
for _, ev in ipairs(data.events or {}) do
if ev.client_id ~= CLIENT_ID then
local d = ev.event_data or {}
if ev.event_type == "block_created" then
local part = Instance.new("Part")
part.Size = Vector3.new(d.sx or 4, d.sy or 4, d.sz or 4)
part.Position = Vector3.new(d.x or 0, d.y or 5, d.z or 0)
part.Anchored = true
part.Parent = workspace
end
end
lastEventId = ev.id or lastEventId
end
end
end
------------------------------------------------
-- API PÚBLICA PRA USAR
------------------------------------------------
local Sync = {}
function Sync.CreateBlock(pos)
sendEvent("block_created", {
x = pos.X,
y = pos.Y,
z = pos.Z,
sx = 4,
sy = 4,
sz = 4
})
end
------------------------------------------------
-- LOOPS
------------------------------------------------
task.spawn(function()
while true do
pollChat()
task.wait(0.5)
end
end)
task.spawn(function()
while true do
pollEvents()
task.wait(1)
end
end)
print("SYNC TOTAL INICIADO (SEM DEMO)")
return Sync



Legal de mais