(again) how to make stud replacement script

i wrote a post about this subject but i wasnt very clear about it. so heres what i need

i need a script that replaces the stud,inlet,weld all be able to swicth them.

before/in studio using resurface to place studs etc:

afther/when the game is running: it replaces the studs with textures with older ones

a video that explains it better is this one:

this is pretty much what i need.

please help i have bin stumped on this for a bit and cant figure it out. ill try to better explain myself if i need to. give me a bit to respond cuz im a bit busy at times

1 Like

What I would do is simply tag all of the texture parts using a collective tag such as “StudTexture” and then create a script in server script service that will use CollectionService to collect all the stud textures and replace them with the new asset ID.

For example:

local CollectionService = game:GetService("CollectionService")

for _, texture in ipairs(CollectionService:GetTagged("StudTexture")) do
    if texture:IsA("Texture") then
        texture.Texture = "new asset id"
    end
end

You can tag instances using CollectionService using the properties tool.

1 Like

You can check the part’s SurfaceAppeareance (hidden part property) and set it to Enum.SurfaceType.Smooth. Then, you’d need to give every face that had a SurfaceType a texture.

Here I came up with a small snippet of code that would do the trick:

--!strict

-- Textures used for replacing surfaces.
local surfacesToTextures = {
	[Enum.SurfaceType.Glue] = "rbxassetid://3527578761",
	[Enum.SurfaceType.Inlet] = "rbxassetid://2881469226",
	[Enum.SurfaceType.Studs] = "rbxassetid://2881013914",
	[Enum.SurfaceType.Universal] = "rbxassetid://2881487862",
	[Enum.SurfaceType.Weld] = "rbxassetid://3447813050",
}

-- Dictionary of surface faces and their respective face name (for use in Enum.NormalId)
local surfaceFaces: { [string]: string } = {
	["TopSurface"] = "Top", 
	["FrontSurface"] = "Front", 
	["LeftSurface"] = "Left", 
	["BackSurface"] = "Back", 
	["RightSurface"] = "Right", 
	["BottomSurface"] = "Bottom"
}

local textureTemplate = Instance.new("Texture")
textureTemplate.StudsPerTileU = 2
textureTemplate.StudsPerTileV = 4

-- Iterate every part in the workspace and replace the surface with a texture.
for _, part: Part in workspace:GetDescendants() do
	if part:IsA("BasePart") then
		
		for surface, textureId in surfacesToTextures do
			
			for surfaceFace, face in surfaceFaces do
				local SurfaceValue = part[surfaceFace]
				if SurfaceValue == surface then
					local Texture = textureTemplate:Clone()
					Texture.Texture = textureId
					Texture.Transparency = part.Transparency
					Texture.Face = Enum.NormalId[face]
					Texture.Parent = part
					part.TopSurface = Enum.SurfaceType.Smooth
				end
			end
		end
	end
end

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