What I want is basicly a lobby where players can create servers, and join them, and it will save when they leave. Basicly like in blockate. How do I achieve this? Thanks!
you mean saving the blocks the player have placed?
datastoreservice can save strings pretty sure, so basically
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local blocks = DataStoreService:GetDataStore("Blocks")
-- Rebuild cframes (same as before)
local function deserialize(data : string,folderName : string)
if not data or data == "" then return end
local allParts : {string} = string.split(data, "|")
-- Create a folder for the player's blocks (optional)
local folder = Instance.new("Folder")
folder.Name = folderName
folder.Parent = workspace
for _, storedPos : string in ipairs(allParts) do
if storedPos ~= "" then
local values : {string} = string.split(storedPos, ",")
for i,v in ipairs(values) do
values[i] = tonumber(v)
end
local posX,posY,posZ = values[1], values[2], values[3]
local rotX,rotY,rotZ = values[4], values[5], values[6]
local cf = CFrame.new(posX,posY,posZ) * CFrame.Angles(rotX,rotY,rotZ)
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(4,4,4)
part.CFrame = cf
part.Parent = folder
end
end
end
-- Serialize the player's blocks
local function serialize(parts : {BasePart})
local result = {}
for _, part : BasePart in ipairs(parts) do
local cf = part.CFrame
local pos = cf.Position
local rx,ry,rz = cf:ToOrientation()
-- "posX,posY,posZ,rotX,rotY,rotZ"
local s = table.concat({
tostring(pos.X),
tostring(pos.Y),
tostring(pos.Z),
tostring(rx),
tostring(ry),
tostring(rz)
},",")
table.insert(result, s)
end
return table.concat(result, "|")
end
-- GET
Players.PlayerAdded:Connect(function(player)
local success, data = pcall(function()
return blocks:GetAsync(player.UserId)
end)
if success and data then
deserialize(data,tostring(player.UserId))
end
end)
-- SAVE
Players.PlayerRemoving:Connect(function(player)
-- Assuming you put all blocks in workspace.Blocks/<playerName>
local folder = workspace.Blocks:FindFirstChild(tostring(player.UserId))
if folder then
local parts = folder:GetChildren()
local dataString = serialize(parts)
pcall(function()
blocks:SetAsync(player.UserId, dataString)
end)
end
end)
I also need the servers and lobby. I said it above.
to make the blockate lobby u can use the place APIs that roblox offers to clone places and teleport to servers, this is how most games with tp lobbies work.
this function saves the place so u don’t need a datastore for it
thank you so much!!! :3 i was thinking of using datastores and tables to save but theres alot easier option! you da best!!!