.Source and String help

Context:

  • I’m Making a plugin for a friend to make things more productive and easier, her game is a outfit shop that works with modules to set up humanoid description in the mannequins, but everytime they want to modify it they’ll need to testplay to check if the mannequins are loading alright, so instead of doing that i’m trying to set-up a plugin that their team can use to fast set-up and preview aswell the mannequins, however i’m barely finding how .Source works, i’m kinda confused, so far i could understand it is mainly based on string.

What do i need help with:

  • Setting up the .Source correctly, changing the modules values to the one inserted into the textButton
    image
Module Code (placerholder one)
return {
	LayeredClothing = {
		TShirt = nil,

		Shirt = nil,

		Pants = nil,

		Jacket = nil,

		Sweater = nil,

		Shorts = nil,

		LeftShoe = nil,

		RightShoe = nil,

		DressSkirt = nil
	},

	ClassicClothing = {
		GraphicTShirt = nil,

		Shirt = nil,

		Pants = nil
	},

	Accessories = {
		BackAccessory = nil,

		FaceAccessory = nil,

		FrontAccessory = nil,

		HairAccessory = nil,

		HatAccessory = nil,

		NeckAccessory = nil,

		ShoulderAccessory = nil,

		WaistAccessory = nil
	},

	Animation = {
		ClimbAnimation = nil,

		FallAnimation = nil,

		IdleAnimation = nil,

		JumpAnimation = nil,

		MoodAnimation = nil,

		RunAnimation = nil,

		SwimAnimation = nil,

		WalkAnimation = nil
	},

	BodyParts = {
		Face = nil,

		Head = nil,

		LeftArm = nil,

		LeftLeg = nil,

		RightArm = nil,

		RightLeg = nil,

		Torso = 48474356
	},

	BodyColors = {
		HeadColor = Color3.new(1, 1, 1),

		LeftArmColor = Color3.new(1, 1, 1),

		LeftLegColor = Color3.new(1, 1, 1),

		RightArmColor = Color3.new(1, 1, 1),

		RightLegColor = Color3.new(1, 1, 1),

		TorsoColor = Color3.new(1, 1, 1)
	},

	Scale = {
		BodyTypeScale = nil,

		DepthScale = nil,

		HeadScale = nil,

		HeightScale = nil,

		ProportionScale = nil,

		WidthScale = nil
	}
}
entire Plugin Code (not complete)
--//Plugin made for WRYNX Outfit Shop use! {By NightlyOne. / XPotatoX }

--[[

	⚠ BE SURE TO CONTACT ME OR SOMEONE WITH KNOWLEDGE ON THIS PLUGIN BEFORE USING IT! ⚠
	
	This is not recommended for anything else than modifying the Mannequins inside the Wrynx Place!

]]

--//Services
local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")
local RunService = game:GetService("RunService")

--//Plugin Info
local Toolbar = plugin:CreateToolbar("Wrynx Plugins")
local ManagerPlugin = plugin:CreateButton(
	"WRYNX | Mannequins Manager",
	"Manage easily mannequins inside Wrynx!",
	"rbxassetid://15487786096"
)

--//Variables
local ScreenGui = script.Parent
local Background = ScreenGui:WaitForChild("Background")
local ScrollingFrame = Background:WaitForChild("ScrollingFrame")
local Viewport = Background:WaitForChild("Viewport")
local Settings = Background:WaitForChild("Settings")

local hbConnection
local hbConnection1
local hbConnection2

local DefDescription

--//Buttons
local Buttons = {
	BodyParts = ScrollingFrame:WaitForChild("BodyParts");
	Animations = ScrollingFrame:WaitForChild("Animations");
	Scale = ScrollingFrame:WaitForChild("Scale");
	LayeredClothing = ScrollingFrame:WaitForChild("LayeredClothing");
	ClassicClothing = ScrollingFrame:WaitForChild("ClassicClothing");
	Accessories = ScrollingFrame:WaitForChild("Accessories");
	BodyColors = ScrollingFrame:WaitForChild("BodyColors");
}

--//Functions
local function recreateModule(module: ModuleScript)
	local newModule = Instance.new("ModuleScript")
	newModule.Parent = module.Parent
	
	local source = {
		LayeredClothing = {
			TShirt = nil,

			Shirt = nil,

			Pants = nil,

			Jacket = nil,

			Sweater = nil,

			Shorts = nil,

			LeftShoe = nil,

			RightShoe = nil,

			DressSkirt = nil
		},

		ClassicClothing = {
			GraphicTShirt = nil,

			Shirt = nil,

			Pants = nil
		},

		Accessories = {
			BackAccessory = nil,

			FaceAccessory = nil,

			FrontAccessory = nil,

			HairAccessory = nil,

			HatAccessory = nil,

			NeckAccessory = nil,

			ShoulderAccessory = nil,

			WaistAccessory = nil
		},

		Animation = {
			ClimbAnimation = nil,

			FallAnimation = nil,

			IdleAnimation = nil,

			JumpAnimation = nil,

			MoodAnimation = nil,

			RunAnimation = nil,

			SwimAnimation = nil,

			WalkAnimation = nil
		},

		BodyParts = {
			Face = nil,

			Head = nil,

			LeftArm = nil,

			LeftLeg = nil,

			RightArm = nil,

			RightLeg = nil,

			Torso = 48474356
		},

		BodyColors = {
			HeadColor = Color3.new(1, 1, 1),

			LeftArmColor = Color3.new(1, 1, 1),

			LeftLegColor = Color3.new(1, 1, 1),

			RightArmColor = Color3.new(1, 1, 1),

			RightLegColor = Color3.new(1, 1, 1),

			TorsoColor = Color3.new(1, 1, 1)
		},

		Scale = {
			BodyTypeScale = nil,

			DepthScale = nil,

			HeadScale = nil,

			HeightScale = nil,

			ProportionScale = nil,

			WidthScale = nil
		}
	}
	
	local _source = game:GetService("HttpService"):JSONEncode(source):gsub("%[",""):gsub("%]",""):gsub(",", ", ")
	
	
	for i,v in require(newModule) do
		for k,j in v do
			j = module[i][k]
		end
	end
	
	
	
end

local function OpenTool()
	if ScreenGui.Enabled then
		ScreenGui.Enabled = false
		if hbConnection then hbConnection:Disconnect() end
		
	else
		ScreenGui.Enabled = true
		local clothingHolder = Instance.new("ModuleScript", ScreenGui)
		clothingHolder.Name = "ClothingH"
		local selected = Selection:Get()
		
		task.spawn(function()
			hbConnection = RunService.Heartbeat:Connect(function()
				selected = Selection:Get()
				
				if #selected == 0 or nil then
					Background.Warning.Visible = true
				else
					Background.Warning.Visible = false
				end
				
			end)
		end)
		
		task.spawn(function()
			-- preview
			while ScreenGui.Enabled do
				if selected and selected[1]:FindFirstChild("Clothing") then
					if #selected ~= 1 then
						Viewport.ViewportFrame.Warning.Visible = true
					elseif #selected == 1 then
						Viewport.ViewportFrame.WorldModel:ClearAllChildren()
						local Description = Instance.new("HumanoidDescription", ScreenGui)
						
						for _,n in require(selected[1]:FindFirstChild("Clothing")) do
							for j,m in n do
								Description[j] = m
							end
						end
						
						local mqn = game:GetService("Players"):CreateHumanoidModelFromDescription(Description, selected[1].Humanoid.RigType)
						
						Description:Destroy()
						
						mqn.Parent = Viewport.ViewportFrame.WorldModel
						
						if Viewport.ViewportFrame:FindFirstChild("Camera") then
							Viewport.ViewportFrame:FindFirstChild("Camera"):Destroy()
						end
						
						local camera = Instance.new("Camera")
						local viewportCamera = Instance.new("Camera")
						Viewport.ViewportFrame.CurrentCamera = viewportCamera
						viewportCamera.Parent = Viewport.ViewportFrame
						viewportCamera.CFrame = CFrame.new(mqn.HumanoidRootPart.Position - Vector3.new(0, 0, 5.5)) * CFrame.Angles(0, math.rad(180), 0)

					end
				end
				task.wait(1)
			end
		end)
		
		for _,bt in ScrollingFrame:GetChildren() do
			if bt:IsA("TextButton") then
				bt.MouseButton1Click:Connect(function()
					recreateModule(selected[1]:FindFirstChild(""))
					for _,nt in Settings.ScrollingFrame:GetChildren() do
						if nt:IsA("TextButton") and nt.Name ~= "Template" then
							nt:Destroy()
						end
					end
					
					if #selected == 1 then
						for i,v in require(selected[1]:FindFirstChild("Clothing"))[bt.Name] do
							
							local template = Settings.ScrollingFrame.Template:Clone()
							template.Name = i
							template.Text = i
							template.TextButton.MouseButton1Click:Connect(function()
								local result = template.TextBox
								
								local Clothing
								
							end)
						end
					end
				end)
			end
		end
		
		task.spawn(function()
			while ScreenGui.Enabled and #selected > 0 do
				
				
				
				
				task.wait(1)
			end
		end)
		
	end
end 

  • So as you can see in the Module code and the simple ui i made, i want to do so if they press the checkmark button with the id written it will be applied inside the module scripts.

Any help, tips and feedback is highly appreciated!

1 Like
button.MouseButton1Click:Connect(function()
themodule.Source = themodule.Source .. [[
]] textlabel.Text --[[assuming you change the text of the gui every time]] .. " = " .. textbox.Text 
end)

if you need more help tell me

1 Like

You should add a ; in the end of the string so the compiler can read it.

1 Like

Sorry if i didn’t explained very well, but here is an example:

there we have this module:

local a = { 
information = "info";
color = 2;
number = 9;

and then i want to make changes inside the plugin to be able to apply it inside the module.
e.g writing a new value inside the plugin ui that will info to newinfo, 2 to 4, 9 to 18 etc…

local a = {
information "newinfo";
color = 4;
number = 18;
1 Like

In order, to make it, you should use string.gsub.

Here is a code i made for you:

-- !!! Warn: All your indexes(e.g. Shirt = nil) should have comma at the end.

-- to -> Is what index to change(e.g. Shirt)
-- ID -> Clothing ID(e.g. 1111111111111, can be string or number, like 'rbxassetid://')
-- module -> Path to module script(e.g. game.ServerStorage.Module)
local function ChangeSourceCode(to: string, ID: string, module: ModuleScript)
	local replacement = string.format("%s = %s,", to, tostring(ID))
	module.Source = string.gsub(module.Source, string.format("%s = .-,", to), replacement)
end

(P.S. - Edited it, now after you changed value, you can change it again)

2 Likes

this is exactly i needed, but a question, what if inside the module isn’t " = nil"? Is there a way of like it change that “.Source line” in a way that dont matter if the “=” is nil, a number or a string, it will be replaced by the parameter “to”?
like, what if

-- source (example)
[[ { A = 1; B = 2; C = "A"; D = nil} ]]

-- replacement
ChangeSourceCode("A", "50", moduleScript) -- changing A (1) to A ("50")
ChangeSourceCode("B", 50, moduleScript) -- changing B (2) to B (50)
ChangeSourceCode("C", "Hi", moduleScript) -- Changing C ("Hi") 
1 Like

Yep! I noticed it, and changed code, copy&paste it again, and it’ll work like a charm! :wink:

OH, AND looks like you have same indexes, like Shirt & Pants(in LayeredClothing and ClassicClothing). I heavily recommend change their index to ClassicShirt and ClassicPants, because script will change all indexes with given name, so in situations where u want to set up Layered Clothing Shirt ID, script will change this value in ClassicShirts as well.

2 Likes

Mhm, i’ll try to see what i can do, but both layered and classic Shirt and Pants have the same name because the server script inside server script service does loops to create a humanoid description based in that exact module :stuck_out_tongue: Ty for the help!

2 Likes

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