Hi!
I have a DS script that should load parts, and then change their color, but it’s not working.
It is still creating the parts though.
Code:
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Constants = require(ReplicatedStorage.Modules.GetConstants)
local ColorDataStore = {}
ColorDataStore = DataStoreService:GetDataStore("ColorDataStore"):GetAsync("main") or {}
local Min = 0 - (Constants.CanvasSize / 2)
local Max = 0 + (Constants.CanvasSize / 2)
local function GetColor(x, z)
local Row, Collum
pcall(function()
Row = ColorDataStore[z]
end)
if Row then
pcall(function()
Collum = Row[x]
end)
if Collum then
return Collum
end
end
end
for x = Min, Max, Constants.TileSize do
if not ColorDataStore[(x + Min) / Constants.TileSize] then ColorDataStore[(x + Min) / Constants.TileSize] = {} end
spawn(function()
for z = Min, Max, Constants.TileSize do
--"a3a2a5"
if not ColorDataStore[(x + Min) / Constants.TileSize][(z + Min) / Constants.TileSize] then
ColorDataStore[(x + Min) / Constants.TileSize][(z + Min) / Constants.TileSize] = "a3a2a5"
end
local NewTile = Instance.new("Part")
NewTile.Size = Vector3.new(Constants.TileSize, 1, Constants.TileSize)
NewTile.Position = Vector3.new(x, Constants.Y_Position, z)
NewTile.Anchored = true
NewTile.TopSurface = Enum.SurfaceType.Smooth
local Color = GetColor((x + Min) / Constants.TileSize, (z + Min) / Constants.TileSize)
ColorDataStore[(x + Min) / Constants.TileSize][(z + Min) / Constants.TileSize] = Color
if Color then NewTile.Color = Color3.fromHex(Color) end
NewTile.Parent = workspace:WaitForChild("Tiles")
task.wait(0.1)
end
end)
task.wait(0.1)
end
--warn(ColorDataStore) --dangerous lol
while task.wait(60) do
warn("Saving data...")
local Packed = {}
for z = Min, Max, Constants.TileSize do
for x = Min, Max, Constants.TileSize do
local Color = GetColor((x + Min) / Constants.TileSize, (z + Min) / Constants.TileSize)
ColorDataStore[(x + Min) / Constants.TileSize][(z + Min) / Constants.TileSize] = Color
table.insert(Packed, Color)
end
end
local success, errormessage = pcall(function()
DataStoreService:GetDataStore("ColorDataStore"):SetAsync("main", Packed)
end)
if not success then warn(errormessage) end
end
Thanks for any help!