This is the :Set()
function on the serverside.
bunkernameStore:Set(new_name)
I made a function that uses new_name
as a parameter, and my event listener uses the parameter sent by the remote event in the function.
Also heres my entire script now that i think about it, datastore2 will be the only thing ill have major trouble with, i should be fine for the rest, and i wont need to supply anymore scripts as ill be fine making the game by myself.
DataStore2 = require(game:GetService("ServerScriptService").DataStore2)
ServerStorage = game:GetService("ServerStorage")
Players = game:GetService("Players")
ReplicatedStorage = game.ReplicatedStorage
objectstore = ReplicatedStorage.bunker_obj_storage
default_omega_coins, default_likes, default_wins = 0, 0, 0
default_bunker_terrain_position = {
Vector3.new(26.927,-33.383,-540.507)
}
default_bunker_terrain_size = {
Vector3.new(1,1,1)
}
default_bunker_terrain_rotation = {Vector3.new(0,0,0)
}
default_bunker_materials = {
"Mud",
}
DataStore2.Combine(
"Test30", "Played", "Wins", "Ωmega Coins", "Likes", "bunker_name", "object_name",
"object_position", "object_rotation", "terrain_position", "terrain_rotation", "terrain_size", "terrain_materials"
)
Players.PlayerAdded:Connect(function(Player)
winsStore = DataStore2("Wins", Player)
coinStore = DataStore2("Ωmega Coins", Player)
likesStore = DataStore2("Likes", Player)
bunkernameStore = DataStore2("bunker_name", Player)
objectnameStore = DataStore2("object_name", Player)
objectpositionStore = DataStore2("object_position", Player)
objectrotationStore = DataStore2("object_rotation", Player)
terrainpositionStore = DataStore2("terrain_position", Player)
terrainrotationStore = DataStore2("terrain_rotation", Player)
terrainsizeStore = DataStore2("terrain_size", Player)
-- :Get()Variables
objectpositionGet = DataStore2("object_position", Player):Get({})
objectrotationGet = DataStore2("object_rotation", Player):Get({})
terrainpositionGet = DataStore2("terrain_position", Player):Get(default_bunker_terrain_position)
terrainrotationGet = DataStore2("terrain_rotation", Player):Get(default_bunker_terrain_rotation)
terrainsizeGet = DataStore2("terrain_size", Player):Get(default_bunker_terrain_size)
terrainmaterialsStore = DataStore2("terrain_materials", Player)
terrainmaterialsGet = DataStore2("terrain_materials", Player):Get(default_bunker_materials)
local played = Instance.new("BoolValue", Player)
played.Name = "played"
if terrainmaterialsStore[1] then
played = true
end
local leaderstats = Instance.new("Folder") do
leaderstats.Name = "leaderstats"
end
local wins = Instance.new("IntValue") do
wins.Name = "Wins"
wins.Parent = leaderstats
end
local omega_coins = Instance.new("IntValue") do
omega_coins.Name = "O$"
omega_coins.Parent = leaderstats
end
local likes = Instance.new("IntValue") do
likes.Name = "Likes"
likes.Parent = leaderstats
end
leaderstats.Parent = Player
function save_to_model(player, bunkernameStore) ---------------------------------------------------- function start
local newMap = ServerStorage.empty_map:Clone() do
newMap.Name = Player.Name
local name = Instance.new("StringValue", newMap.params)
if bunkernameStore then
name.Value = bunkernameStore
else
name.Value = "Bunker Construction Site"
end
local offset = Instance.new("NumberValue", newMap.params)
--offset.Value = Player:WaitForChild("designated_bunker_position")
end
local terrain = newMap.terrain:WaitForChild("cubes")
print (terrainmaterialsStore)
print (terrainmaterialsGet)
for i, v in pairs(terrainmaterialsGet) do
print (i) print(v)
local Part = Instance.new("Part") do
Part.Name = v
Part.CFrame = CFrame.new(terrainpositionGet[i])
Part.Size = Vector3.new(terrainsizeGet[i])
Part.Orientation = Vector3.new(terrainrotationGet[i])
Part.Parent = terrain
Part.Anchored = true
Part.Transparency = 1
Part.CanCollide = false
newMap.Parent = game.Workspace.maps
end
for i, v in pairs (objectnameStore:Get({})) do
local obj = objectstore[v]:Clone()
obj.Position = CFrame.new(objectpositionGet[i])
obj.Orientation = Vector3.new(objectrotationGet[i])
end
end
end --------------------------------------------------------------------------------------------- function end
function model_to_save(new_name) ---------------------------------------------------------function start
local terrain = workspace.maps[Player.Name].terrain:WaitForChild("cubes"):GetChildren()
local mapobj = workspace.maps[Player.Name].obj:GetChildren()
bunkernameStore:Set(new_name)
terrainposition,
terrainrotation,
terrainsize,
terrainmaterials,
objectposition,
objectrotation = {},{},{},{},{},{}
for i = 1, #terrain do
local child = terrain[i]
if child:IsA("Part") then
terrainposition[i] = Vector3.new(child.Position.X,child.Position.Y,child.Position.Z)
terrainrotation[i] = Vector3.new(child.Rotation.X,child.Rotation.Y,child.Rotation.Z)
terrainsize[i] = Vector3.new(child.Size.X,child.Size.Y,child.Size.Z)
terrainmaterials[i] = child.name
end
end
for i = 1, #mapobj do
local objchild = mapobj[i]
if objchild:IsA("Model") then
local partchild = #mapobj[i]
for i = 1, #partchild do
if partchild:IsA("Part", "MeshPart") then
objectposition = Vector3.new(partchild[i].Position.X,partchild[i].Position.Y,partchild[i].Position.Z)
objectrotation = Vector3.new(partchild[i].Orientation.X,partchild[i].Orientation.Y,partchild[i].Orientation.Z)
end
end
end
end
terrainpositionStore:Set(terrainposition)
terrainrotationStore:Set(terrainrotation)
terrainsizeStore:Set(terrainsize)
terrainmaterialsStore:Set(terrainmaterials)
objectpositionStore:Set(objectposition)
objectrotationStore:Set(objectrotation)
end -------------------------------------------------------------------------------------------function end
ReplicatedStorage:WaitForChild("load_map").OnServerEvent:Connect(function(player)
save_to_model(player)
end)
ReplicatedStorage:WaitForChild("save_map").OnServerEvent:Connect(function(name)
model_to_save(name)
end)
end)