Dear scripters. I rarely see someone that want to improve a code. Anyways, let’s go straight to the point.
How can I improve this code in any way ?
local viewportFrame = playerGui.DeepScreen.Shop.ScrollingFrame.AccessoriesPage.ViewportFrame
local function createViewport(accessory)
local viewportAccessory = accessory:Clone()
local accessoryViewport = viewportFrame:Clone()
local worldModel = accessoryViewport.WorldModel
local VPFcam = Instance.new("Camera")
VPFcam.Parent = accessoryViewport
VPFcam.CFrame = CFrame.new(0, 0, 0)
accessoryViewport.CurrentCamera = VPFcam
viewportAccessory.Parent = accessoryViewport:WaitForChild("WorldModel")
viewportAccessory.Handle.CFrame = CFrame.new(Vector3.new(0, 0, -2.3), Vector3.new(0, 0, 0))
accessoryViewport.Name = viewportAccessory.Name
accessoryViewport.MouseMoved:Connect(function()
viewportAccessory.Handle.CFrame *= CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
end)
accessoryViewport.InputBegan:Connect(function(input) --devforum how to improve code..
if input.UserInputType == Enum.UserInputType.MouseButton1 then
SoundService.UISFX.Equip2:Play()
for _, charAccessory: Accessory in pairs(character:GetChildren()) do
if charAccessory:IsA("Accessory") then
if charAccessory.Name == accessory.Name or charAccessory.AccessoryType.Name == accessory.AccessoryType.Name then
charAccessory.Parent = ReplicatedStorage.Accessories
accessory.Parent = character
accessoryViewport.Parent:FindFirstChild(accessory.Name).BackgroundColor3 = Color3.new(0.266667, 1, 0)
accessoryViewport.Parent:FindFirstChild(charAccessory.Name).BackgroundColor3 = Color3.new(1, 1, 1)
accessoryViewport.Parent:FindFirstChild(accessory.Name).UIStroke.Color = Color3.new(0.266667, 1, 0)
accessoryViewport.Parent:FindFirstChild(charAccessory.Name).UIStroke.Color = Color3.new(0, 0, 0)
else
accessoryViewport.Parent:FindFirstChild(accessory.Name).BackgroundColor3 = Color3.new(0.266667, 1, 0)
accessoryViewport.Parent:FindFirstChild(accessory.Name).UIStroke.Color = Color3.new(0.266667, 1, 0)
accessory.Parent = character
end
elseif not character:FindFirstChildOfClass("Accessory") then
accessoryViewport.Parent:FindFirstChild(accessory.Name).BackgroundColor3 = Color3.new(0.266667, 1, 0)
accessoryViewport.Parent:FindFirstChild(accessory.Name).UIStroke.Color = Color3.new(0.266667, 1, 0)
accessory.Parent = character
end
end
end
end)
return accessoryViewport
end
local function setUpViewports()
local accessoriesFolder = ReplicatedStorage:WaitForChild("Accessories")
for _, accessory in ipairs(accessoriesFolder:GetChildren()) do
createViewport(accessory).Parent = viewportFrame.Parent
end
end
The only improvment I actually want to learn is how to make this code better (shorter and nicer)
if charAccessory:IsA("Accessory") then
if charAccessory.Name == accessory.Name or charAccessory.AccessoryType.Name == accessory.AccessoryType.Name then
charAccessory.Parent = ReplicatedStorage.Accessories
accessory.Parent = character
accessoryViewport.Parent:FindFirstChild(accessory.Name).BackgroundColor3 = Color3.new(0.266667, 1, 0)
accessoryViewport.Parent:FindFirstChild(charAccessory.Name).BackgroundColor3 = Color3.new(1, 1, 1)
accessoryViewport.Parent:FindFirstChild(accessory.Name).UIStroke.Color = Color3.new(0.266667, 1, 0)
accessoryViewport.Parent:FindFirstChild(charAccessory.Name).UIStroke.Color = Color3.new(0, 0, 0)
else
accessoryViewport.Parent:FindFirstChild(accessory.Name).BackgroundColor3 = Color3.new(0.266667, 1, 0)
accessoryViewport.Parent:FindFirstChild(accessory.Name).UIStroke.Color = Color3.new(0.266667, 1, 0)
accessory.Parent = character
end
elseif not character:FindFirstChildOfClass("Accessory") then
accessoryViewport.Parent:FindFirstChild(accessory.Name).BackgroundColor3 = Color3.new(0.266667, 1, 0)
accessoryViewport.Parent:FindFirstChild(accessory.Name).UIStroke.Color = Color3.new(0.266667, 1, 0)
accessory.Parent = character
end
Because it feels like
part.Transparency = 0.1
task.wait(0.1)
part.Transparency = 0.2
task.wait(0.1)
part.Transparency = 0.3
task.wait(0.1)
part.Transparency = 0.4
task.wait(0.1)
part.Transparency = 0.5
etc..
Thanks for your time. Goodluck flexing with your experience.