server script that creates the base
local rep = game:GetService("ReplicatedStorage")
local base = rep.create_base
local bases = game:GetService("Workspace")["owned plots"]
base.OnServerEvent:Connect(function(player)
for _,base_values in pairs(player.Base:GetChildren()) do
wait(1)
for i,v in pairs(bases:GetChildren()) do
if v.Name:split(" ")[2] == player.Name then
for i = 1,player.Amount.Value do
local part = Instance.new("Part",v)
print(part:GetFullName())
part.CanCollide = true
part.Anchored = true
local position = base_values.Position.Value:split(", ")
local x = tonumber(position[1])
local y = tonumber(position[2])
local z = tonumber(position[3])
part.Position = v.Position + Vector3.new(x,y,z)
local orientation = base_values.Orientation.Value:split(", ")
local x = tonumber(orientation[1])
local y = tonumber(orientation[2])
local z = tonumber(orientation[3])
part.Orientation = Vector3.new(x,y,z)
local color = base_values.Color.Value:split(", ")
local x = tonumber(color[1])
local y = tonumber(color[2])
local z = tonumber(color[3])
part.Color = Color3.fromRGB(x,y,z)
local material = base_values.Material.Value
part.Material = Enum.Material[material]
part.Name = base_values.name.Value
local size = base_values.Size.Value:split(", ")
local x = tonumber(size[1])
local y = tonumber(size[2])
local z = tonumber(size[3])
part.Size = Vector3.new(x,y,z)
end
end
end
end
end)
server script that saves the base
local names = {}
local Datastore = game:GetService("DataStoreService"):GetDataStore("base_storage")
game:GetService("ReplicatedStorage").save_base.OnServerEvent:Connect(function(player)
print("fired")
local place
local plot
--if not table.find(names,player,1) then
local Key = "Player-ID:" .. player.UserId
local base = player.Base
for i,v in pairs(base:GetChildren()) do
print("saving")
wait(5)
if v.Value ~= "" then return end
for _,bases in pairs(game:GetService("Workspace")["owned plots"]:GetChildren()) do
if bases.Name:split(" ")[2] == player.Name then
local split = v.Position.Value:split(", ")
local numbervalue = Vector3.new(tonumber(split[1]),tonumber(split[2]),tonumber(split[3]))
local distance = tostring(bases.Position - numbervalue)
print(distance)
local valuestosave = {player.Amount.Value,
v.Name,
distance,
v.Orientation.Value,
v.Color.Value,
v.Material.Value,
v.Size.Value,
v.name.Value
}
Datastore:SetAsync(Key, valuestosave)
end
-- print(bases.Position - place)
end
--names = {}
end
print("saved")
--end
end)
i need this to put the parts i save in the same position of the new base as the old position of the old base
