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)
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
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 = 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???
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
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?
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