so recently ive been doing a script that with the click of a button changes the scheme of a car’s body depending on its given value.
thing is, im doing it the very old and bad/overcomplicated way since i dont know how to properly optimize it,
which in turn is making me lose a LOT of time just organizing the schemes + making it appear in the rotation.
heres the script:
-- Player
local Plr = script.Parent.Parent.Parent.Parent.Parent.Parent.Name
-- Gets the player car
local Car = game.Workspace.Cars:WaitForChild(Plr.. "Car")
-- Scheme Value
local Value = script.Parent.SchemeValue
-- The car body parts
local Body = Car:FindFirstChild("Body")
-- Scheme List
local Scheme0 = "rbxassetid://11170714394"
local Scheme1 = "rbxassetid://11379831515"
local Scheme2 = "rbxassetid://11229241277"
local Scheme3 = "rbxassetid://11229244214"
local Scheme4 = "rbxassetid://11379843052"
local Scheme5 = "rbxassetid://11379861502"
local Scheme6 = "rbxassetid://11379862505"
local Scheme7 = "rbxassetid://11379863968"
local Scheme8 = "rbxassetid://11229247573"
script.Parent.SchemeValue.Changed:Connect(function()
if Value.Value == 0 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme0
end
end
elseif Value.Value == 1 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme1
end
end
elseif Value.Value == 2 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme2
end
end
elseif Value.Value == 3 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme3
end
end
elseif Value.Value == 4 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme4
end
end
elseif Value.Value == 5 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme5
end
end
elseif Value.Value == 6 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme6
end
end
elseif Value.Value == 7 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme7
end
end
elseif Value.Value == 8 then
for i, v in pairs(Body:GetDescendants()) do
if v.ClassName == "MeshPart" then
v.TextureID = Scheme8
end
end
end
end)
this one is the shortest of them all, but theres other ones that are awfully long and time consuming.
the script works perfectly fine, but the problem is optimizing it, so any help is highly appreciated!
(and if you are wondering, the scheme value is handled by a separate script)