My topic died so here we go again.
I need to make a script that can 1: save data 2: convert saveable bunker array properties into parts and put them into my map 3: Convert models into datastoreable arrays 4: Offset bunkers to a free position.
Map format explanation:
Each map is stored in game.Workspace.maps and the client makes sure that all maps but the map the player is in is parented to game.ReplicatedStorage.local_map_storage. It also clears any existing terrain and adds new terrain using :FillBlock() on parts in cubes and also in :FillBlock() enum.Material is set to the part’s name.
Function for loading maps (Locally stored module script)
ReplicatedStorage = game.ReplicatedStorage
loaded_map = script.Parent.loaded_map.Value
local_map_storage = ReplicatedStorage.local_map_storage
maps = game.Workspace.maps
maps_children = maps:GetChildren()
storage_children = local_map_storage:GetChildren()
Terrain = game.Workspace.Terrain
local functions = {
load_map = function (area, spawn_area_X, spawn_area_Y, spawn_area_Z, angle_X, angle_Y, angle_Z, use_respawn, transition, transition_name, transition_description, transition_colour)
Terrain:Clear()
ReplicatedStorage.load_area:FireServer(area, spawn_area_X, spawn_area_Y, spawn_area_Z)
maps[loaded_map].Parent = local_map_storage
loaded_map = area
local_map_storage[area].Parent = maps
local map_terrain = maps[loaded_map].terrain
local cubes = map_terrain.cubes:GetChildren()
local spheres = map_terrain.spheres:GetChildren()
for i = 1, #cubes do
local cube_child = cubes[i]
if cube_child:IsA("Part") then
game.Workspace.Terrain:FillBlock(cube_child.CFrame, cube_child.Size, Enum.Material[cube_child.Name])
end
end
print (area.." loaded")
if use_respawn == true then
print ("Using respawn points.")
else
local character = game.Players.LocalPlayer.Character
local pos = CFrame.new(spawn_area_X, spawn_area_Y, spawn_area_Z)
local rot = CFrame.Angles(math.rad(angle_X), math.rad(angle_Y), math.rad(angle_Z))
character.HumanoidRootPart.CFrame = pos * rot
end
end
};
return functions;
It is important that I store the name, position, rotation, and size of blocks to be used with :FillBlock()
To load bunkers from datastore2 I need to have default values for each property and load those in if there is no saved data.
And of course I need to store all other data: Wins, Omega Coins, and Bunker Likes
Save script:
local DataStore2 = require(1936396537)
local ServerStorage = game.ServerStorage
local Workspace = game.Workspace
local Players = game.Players
local default omega_coins = 0
local default_likes = 0
local default_wins = 0
local default_bunker_terrain_position = {CFrame.new(26.927, -33.383, -435.507), CFrame.new(26.927, 23.365, -572.788), CFrame.new(164.479, 23.365, -434.153),
CFrame.new(-110.625, 23.365, -435.236), CFrame.new(25.844, 23.365, -297.955)}
local default_bunker_terrain_size = {Vector3.new(277.27, 8.143, 277.27), Vector3.new(277.27, 108.309, 2.708),Vector3.new(2.166, 108.309, 274.562),Vector3.new(2.166, 108.309, 272.396),Vector3.new(275.104, 108.309, 2.166)}
local default_bunker_terrain_rotation = {CFrame.Angles(0,0,0), CFrame.Angles(0,0,0), CFrame.Angles(0,0,0),
CFrame.Angles(0,0,0), CFrame.Angles(0,0,0)}
local default_bunker_materials = {"Mud","Rock","Rock","Rock","Rock"}
DataStore2.Combine("main", "Wins", "Ωmega Coins", "Likes", "object_name", "object_position", "object_rotation", "terrain-position", "terrain_rotation", "terrain_size", "terrain_materials")
Players.PlayerAdded:Connect(function(plr)
local winsStore = DataStore2("Wins", plr)
local coinStore = DataStore2("Ωmega Coins", plr)
local likesStore = DataStore2("Likes", plr)
local objectnameStore = DataStore2("object_name", plr)
local objectpositionStore = DataStore2("object_position", plr)
local objectrotationStore = DataStore2("object_rotation", plr)
local terrainpositionStore = DataStore2("terrain-position", plr)
local terrainrotationStore = DataStore2("terrain_rotation", plr)
local terrainsizeStore = DataStore2("terrain_size", plr)
local terrainmaterialsStore = DataStore2("terrain_materials", plr)
local leaderstats = Instance.new("Folder",plr) ---leaderstats folder
leaderstats.Name = "leaderstats"
local wins = Instance.new("IntValue",leaderstats) --leaderstats
wins.Name = "Wins"
local omega_coins = Instance.new("IntValue",leaderstats)
omega_coins.Name = "Ωmega $"
local likes = Instance.new("IntValue",leaderstats)
likes.Name = "Likes"
end)
function save_to_model(folder_name, target_location, CFrameoffset)
local newMap = ServerStorage.empty_map:Clone()
newMap.Name = folder_name
newMap.Parent = Workspace
local terrain = newMap.terrain:WaitForChild("cubes")
for i, v in pairs(default_bunker_materials) do
local part = Instance.new("Part")
part.Name = v
-- new block:
part.CFrame = default_bunker_terrain_position*default_bunker_terrain_position[i]
part.Size = default_bunker_terrain_size[i]
part.Parent = terrain
end
end
save_to_model("MrGuyROBLOX's Dungeon", game.Workspace.maps,0,0,0)
I am having trouble with saving data and adding a default value as you can see in my script I am not using the actual datastore for the bunker loading function, I’m using the default values and I need to fix that.