Hello so I am working on a tiny project that edits a room with tweens when a gui button is clicked for the whole server but the issue I got is that the script is too long and takes a while to finish.
each function does something for each part in the model.
Ive tried putting it in one function but when I try it it takes years for it to finsish.
I want to make it do the editing all at once instead of once part at a time.
here is my script.
local TS = game:GetService("TweenService")
game.ReplicatedStorage:WaitForChild("BiomChange").OnServerEvent:Connect(function(plr, Name)
game.ReplicatedStorage:WaitForChild("Styles"):FindFirstChild(Name).Parent = workspace
for i, Chrildren in pairs(script.Parent:GetDescendants()) do
if Chrildren.Name == "Ground" then
local Part = Chrildren
local Goal = {}
Goal.Color = Color3.new(0.054902, 0.486275, 0.054902)
local Tweeninfo = TweenInfo.new(1)
task.wait(0.1)
local partween = TS:Create(Part, Tweeninfo, Goal):Play()
Part.Material = Enum.Material.Grass
end
end
end)
game.ReplicatedStorage:WaitForChild("BiomChange").OnServerEvent:Connect(function(plr, Name)
for i, Chrildren in pairs(script.Parent:GetDescendants()) do
if Chrildren.Name == "1" then
local Part = Chrildren
local Goal = {}
Goal.Transparency = 1
local Tweeninfo = TweenInfo.new(1)
task.wait(0.1)
local partween = TS:Create(Part, Tweeninfo, Goal):Play()
end
end
end)
game.ReplicatedStorage:WaitForChild("BiomChange").OnServerEvent:Connect(function(plr, Name)
for i, Chrildren in pairs(script.Parent:GetDescendants()) do
if Chrildren.Name == "2" then
local Part = Chrildren
local Goal = {}
Goal.Transparency = 1
local Tweeninfo = TweenInfo.new(1.5)
task.wait(0.1)
local partween = TS:Create(Part, Tweeninfo, Goal):Play()
end
end
end)
game.ReplicatedStorage:WaitForChild("BiomChange").OnServerEvent:Connect(function(plr, Name)
for i, Chrildren in pairs(script.Parent:GetDescendants()) do
if Chrildren:IsA("SelectionBox") then
local Part = Chrildren
local Goal = {}
Goal.Color3 = Color3.new(1, 1, 1)
local Tweeninfo = TweenInfo.new(1)
task.wait(0.1)
local partween = TS:Create(Part, Tweeninfo, Goal):Play()
end
end
end)
game.ReplicatedStorage:WaitForChild("BiomChange").OnServerEvent:Connect(function(plr, Name)
for i, Chrildren in pairs(script.Parent:GetDescendants()) do
if Chrildren:IsA("SelectionBox") then
local Part = Chrildren
local Goal = {}
Goal.Transparency = 1
local Tweeninfo = TweenInfo.new(1)
task.wait(0.1)
local partween = TS:Create(Part, Tweeninfo, Goal):Play()
end
end
end)