This is the all program
local Players = game.Players
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("PlayerData")
local RemoteEvent = game.ReplicatedStorage:FindFirstChild("RemoteEvents"):FindFirstChild("SaveImage")
local RemoteEvent2 = game.ReplicatedStorage:WaitForChild("RemoteEvents"):FindFirstChild("SaveVideo")
local RemoteEvent3 = game.ReplicatedStorage:WaitForChild("RemoteEvents"):FindFirstChild("GetVideo")
local DataModule = require(game.ServerScriptService.DataModule)
--[[
Tableの内部構造
{
{R,G,B}
{R,G,B}
{R,G,B}
.
.
.
}
--]]
local function LoadImageFromData(plr,ImageData,val)
local frames = plr:WaitForChild("PlayerGui"):FindFirstChild("Home").Save.inside
local frames2 = plr:WaitForChild("PlayerGui"):FindFirstChild("Home").List.inside
for i,v in pairs(ImageData) do
frames["Frame"..val]:FindFirstChild("G-"..i).BackgroundColor3 = Color3.fromRGB(v[1]*255,v[2]*255,v[3]*255)
frames2["Frame"..val]:FindFirstChild("G-"..i).BackgroundColor3 = Color3.fromRGB(v[1]*255,v[2]*255,v[3]*255)
end
end
RemoteEvent2.OnServerEvent:Connect(function(plr,data,key,speed,title,frames)
DataModule.SaveData(plr,data,key,speed,title,frames)
end)
Players.PlayerAdded:Connect(function(plr)
--プレイヤーの中にグリッドをコピーする--
for i=1, 3, 1 do
local frames = plr:WaitForChild("PlayerGui"):WaitForChild("Home").Save.inside
local G = game.ReplicatedStorage.G
local F1 = frames:FindFirstChild("Frame"..i)
local n = 1
for x = 0 , 31 , 1 do
for y = 0 , 31 , 1 do
local CloneG = G:Clone()
CloneG.Name = "G-"..n
CloneG.Parent = F1
CloneG.Size = UDim2.new(0.03125,0,0.03125,0)
CloneG.Position = UDim2.new(0.03125*y,0,0.03125*x,0)
n = n + 1
end
end
end
--プレイヤーの中にグリッドをコピーする2--
for i=1, 3, 1 do
local frames = plr:WaitForChild("PlayerGui"):WaitForChild("Home").List.inside
local G = game.ReplicatedStorage.G
local F1 = frames:FindFirstChild("Frame"..i)
local n = 1
for x = 0 , 31 , 1 do
for y = 0 , 31 , 1 do
local CloneG = G:Clone()
CloneG.Name = "G-"..n
CloneG.Parent = F1
CloneG.Size = UDim2.new(0.03125,0,0.03125,0)
CloneG.Position = UDim2.new(0.03125*y,0,0.03125*x,0)
n = n + 1
end
end
end
--データをロードする--
local success,err
local Data = {}
local frames = plr:WaitForChild("PlayerGui"):WaitForChild("Home").Save.inside
success,err = pcall(function()
Data = DataStore:GetAsync(plr.UserId)
print(Data)
end)
if success then
if Data then
for i,v in pairs(Data) do
local key = v["key"]
local speed = v["SP"]
local title = v["TT"]
local frames = v["FR"]
if v and speed and title and frames then
LoadImageFromData(plr,v[1],i)
DataModule.SaveData(plr,v,key,speed,title,frames)
end
end
else
end
else
--plr:Kick("Something went wrong, Please rejoin later.")
end
end)
RemoteEvent.OnServerEvent:Connect(function(plr,data,val)
LoadImageFromData(plr,data,val)
end)
RemoteEvent3.OnServerEvent:Connect(function(plr,val)
local data = DataModule.GetData(plr,val)
if data then
local speed = data["SP"]
local frame = data["FR"]
RemoteEvent3:FireClient(plr,data,speed,frame)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errorMsg
success, errorMsg = pcall(function()
local newdata = DataModule.GetData(plr)
DataStore:UpdateAsync(plr.UserId, function(someTable)
local savedata = newdata
return savedata
end)
end)
if success then
print("successfully saved "..plr.Name.."'s Data")
else
print(errorMsg)
end
end)