Stud replacement script

hello. i am currently making a game and a feature i want to include is the abilty to change to studs in the settings to different styles. i have no idea how to script this

a good example of what i am looking for is this video:

(please note it replaces the normal plastic material (with studs and everyhing to the style one he wants)

i would like a script just like the video please.

Should be easy right ?

local part = “your part”
part.Material = “One you want”


local function MaterialReplaceSetting()
local v=workspace.YourMap:GetChildren
v.Material= -- which one you want --
end

local function MaterialReplaceSetting0()
for i,v in ipairs(workspace.YourMap:GetChildren)
v.Material= -- which one you want --

end
end

local function MaterialReplaceSetting1(a,a0) -- in this you need write the instance
a.Material= -- which one you want
-- a0 is basically if you want make selectable Material throught text writing (correctly)

end
2 Likes

The easiest way to do it is the following one:

for _, Object in workspace:GetDescendants() do
	if Object:IsA("Part") then
		Object.Material = Enum.Material.SmoothPlastic
	end
end

However, the most performant way would be to use a custom stud MaterialVariant that you remove/add in the MaterialService.

make a folder in the workspace and put all the parts you want to be converted to studs or what ever inside of it.

Name it to how ever just make sure to change in the script the name of the folder to what youve named it in the wokspace.

i would recomend running this in the command bar as it will save changes to roblox studio but you can put this in a script too.

you can also change the surface type to what ever you want (studs,inlet,ect)

–[[ make sure to copy bellow into where ever you want to run the code not the text above cause you will get an error LOL. --]]

local fold = game.Workspace[‘MyFolder’] --[[ change this to the exact name of your folder in the workspace make sure you leave the quotes and everything else. --]]
local stud_type = Enum.SurfaceType.Studs --[[ stud type, you can custumize this to which one you want --]]

local convert_surface = function(part)
part.TopSurface = stud_type
part.BottomSurface = stud_type
part.LeftSurface = stud_type
part.RightSurface = stud_type
part.FrontSurface = stud_type
part.BackSurface = stud_type
end

local convert = function()
for _,v in pairs(fold) do
if v:IsA(‘BasePart’) or v:IsA(‘Part’) or v:IsA(‘MeshPart’) then
task.spawn(convert_surface,v)
end
end
end task.spawn(convert)

–[[IMPORTANT NOTICE BTW - YOU NEED TO REPLACE THE QUOTATIONS YOURSELF. IDK WHY I CANT TYPE THEM ON THE DEV FORUM PROPERLY IN A WAY YOU CAN JUST COPY AND PASTE… --]]

–[[ if you need help with more instructions or somthing lmk–]]

You are saying something confusing and misleading.
Please format your post more properly.
From your words you are talking about SurfaceType but in the video decals are shown…
What??? :skull:

ipairs,pairs are completelly not needed
Please format text in ```lua to be more pleasant to eye and somewhat readable.
Why are you using task.spawn inside non yieldable function and declearing a function in non idiomatic way?

right sorry about the whole pairs thing idk the difference between using pairs and not all i know is ipairs loops through a table in order and pairs is kinda random.

sorry for not typing strings in a pretty way :point_right::point_left:

idk why i thought task.spawn would help speed it up anyway.

idk how functions are normally declared are they declared like “local function convert()” or sum?
also whats wrong with me writing my code the way i do?

why u say format text are you talking abt the way i write strings?

sorry i wasnt clear i meant this:

i would like a script that can reaplce studs, inlets ,welds, etc like in the video

1 Like

sorry i wasnt clear this is what i meant https://www.youtube.com/watch?v=Y2LRt2DV3lY

well i used this code to replace my studs (note: you must have ur textures as the parent of the script and put this in serverscriptservice or workspace.) hopefully this helps


local Surfaces = {
	[Enum.SurfaceType.Studs] = script.Studs,
	[Enum.SurfaceType.Inlet] = script.Inlet,
	[Enum.SurfaceType.Glue] = script.Glue,
	[Enum.SurfaceType.Weld] = script.Weld,
	[Enum.SurfaceType.Universal] = script.Unviersal
}

function ApplySurface(Part: BasePart)	
	local PartSurfaces = {
		[Enum.NormalId.Top] = Part.TopSurface,
		[Enum.NormalId.Back] = Part.BackSurface,
		[Enum.NormalId.Left] = Part.LeftSurface,
		[Enum.NormalId.Front] = Part.FrontSurface,
		[Enum.NormalId.Right] = Part.RightSurface,
		[Enum.NormalId.Bottom] = Part.BottomSurface,
	}
	
	for Face, Surface in pairs(PartSurfaces) do
		local SurfaceTexture = Surfaces[Surface]
		if not SurfaceTexture then continue end
		
		SurfaceTexture = SurfaceTexture:Clone()
		SurfaceTexture.Parent = Part
		SurfaceTexture.Face = Face
		
		Part[Face.Name .. "Surface"] = Enum.SurfaceType.SmoothNoOutlines
	end
end

for _, Part in workspace:GetDescendants() do
	if Part:IsA("BasePart") then
		if Part:FindFirstChild("Mesh") then continue end -- replace or change this line in case of troubles
		ApplySurface(Part)
	end
end

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