Script For Randomly Selecting A Car Livery Texture

Hello, I am trying to get a working script that will take textures from a list and randomly select one to be used for the police car’s livery upon spawning in. The texture needs to be applied to 8 MeshParts that are in my Model called Livery. The script itself is located in the driver seat.

Something in my code is missing and/or wrong, I just don’t know what it is. This is the code I have as of now.

local textures = { 0001,0002,0003} -- ID's are just place holders for now
local livery = script.Parent.Parent.Body.Body.Livery:GetChildren()

	livery.TextureID = "http://www.roblox.com/asset/?id=" .. textures[math.random(1,#textures)]
end

I don’t have the best scripting ability myself. I appreciate any feedback that could possibly get this working. Hopefully I’ve explained enough information to those of you reading. Thank you.

I think this would work :

local textures = { 0001,0002,0003} -- ID's are just place holders for now
local livery = script.Parent.Parent.Body.Body.Livery
local RandomTexture = textures[math.random(1,#textures)]

for v, Part in pairs(Livery:GetChildren()) do
    Part.TextureID = "rbxassetid://"..RandomTexture
end

Success! I greatly appreciate your help a lot, Thank You!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.