Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Script isent inserting all my parts onto my character (like the outfit), are you able to help me?

in my Script its suppose to put all the parts onto the character like an outfit when they spawn, it is doing it thou. The problem is that its not putting all the unions in, its just leaving the Spots empty.

Here is the Script:

wait(1)--Quick load.
S=script.Parent--Short parent.
P=game.Players.LocalPlayer--Short player.
Name="Red Dino Ranger"--Change this to the name of the morph/model found in "ReplicatedStorage".
Object=""--Just a shortcut, you don't need to change this.

--When you morph your character once you can enable this script again for another morph!
--EX: if P.Data.Costume.Value==2 then Name=="YusukeCostume" end (this script auto-disables).
local Stuff=P.Character:GetChildren()
for i=1,#Stuff do if Stuff[i].ClassName=="CharacterMesh" or Stuff[i].ClassName=="Shirt" or Stuff[i].ClassName=="Pants" then Stuff[i]:Destroy() end end
--This line bellow will make the character completly invisible without a face so the morph can be unique.
--for i=1,#Stuff do if Stuff[i].ClassName=="Part" then Stuff[i].Transparency=1 end end P.Character.Head.Transparency=.99 Face=P.Character.Head:WaitForChild("face") if Face~=nil then Face:Destroy() end

--I made this function to save many scripting lines.
function Weld()
local Model=game.ReplicatedStorage:FindFirstChild(Name)
local Clone=Model:FindFirstChild(Object):Clone() Clone.Parent=P.Character
local Child=Clone:GetChildren()
for i=1,#Child do if Child[i].Name=="Main" then Child[i].Transparency=1 end end
for i=1,#Child do if Child[i].className=="Part" then
local Weld=Instance.new("Weld") Weld.Part0=Clone.Main Weld.Part1=Child[i]
local CJ=CFrame.new(Clone.Main.Position) local C0=Clone.Main.CFrame:inverse()*CJ
local C1=Child[i].CFrame:inverse()*CJ Weld.C0=C0 Weld.C1=C1 Weld.Parent=Clone.Main
end
local Y=Instance.new("Weld")
if Object=="LA" then Y.Part0=P.Character:FindFirstChild("Left Arm")
elseif Object=="LL" then Y.Part0=P.Character:FindFirstChild("Left Leg")
elseif Object=="RA" then Y.Part0=P.Character:FindFirstChild("Right Arm")
elseif Object=="RL" then Y.Part0=P.Character:FindFirstChild("Right Leg")
elseif Object=="TS" then Y.Part0=P.Character:FindFirstChild("Torso")
elseif Object=="HD" then Y.Part0=P.Character:FindFirstChild("Head")
end
Y.Part1=Clone.Main Y.C0=CFrame.new(0, 0, 0) Y.Parent=Y.Part0
end
local Finish=Clone:GetChildren() for i=1,#Finish do Finish[i].Anchored=false Finish[i].CanCollide=false end
end

Object="LA" Weld()--LeftArm
Object="LL" Weld()--LeftLeg
Object="RA" Weld()--RightArm
Object="RL" Weld()--RightLeg
Object="TS" Weld()--Torso
Object="HD" Weld()--Head
script.Disabled=true

1 answer

If you'd have written it yourself, it would be easier to understand. However, it's your lucky day! I am a master of UnionOperations!

Your problem is that you are only welding objects that have the ClassName of "Part". Changing this to "BasePart" will solve all of your problems. Below is a re-written, fixed piece of code. Also, I cleaned up the code so that it's more read-able to those looking at it here on ScriptingHelpers ;)

It should do the same thing as before, but be more efficient and include UnionOperations.

wait(1)
local plr = game.Players.LocalPlayer -- Creates a reference to our Player
local char = plr.Character -- Creates a reference to the Player's Character
local name="Red Dino Ranger"-- The name of the morph/model found in ReplicatedStorage.

local stuff = char:GetChildren()
for i=1,#stuff do 
	local checkingObj = stuff[i]
	if checkingObj.ClassName=="CharacterMesh" or checkingObj.ClassName=="Shirt" or checkingObj.ClassName=="Pants" then 
		checkingObj:Destroy() 
	end 
end

function invisChar()
	for i=1,#stuff do
		local checkingObj = stuff[i]
		if stuff[i].ClassName == "Part" then 
			stuff[i].Transparency=1
		end 
	end 
	char.Head.Transparency=.98
	local face = char.Head:FindForChild("face") 
	if face then 
		face:Destroy() 
	end
end

--invisChar()   --- Uncomment this line if you want the character to become invisible, and the face to be deleted.

local model = game.ReplicatedStorage:FindFirstChild(name)

function Weld(obj,part)
	local Clone = model:FindFirstChild(obj):Clone() 
	Clone.Parent = char
	local Child = Clone:GetChildren()
	for i=1,#Child do
		local chosenObject = Child[i]
		if chosenObject.Name == "Main" then 
			chosenObject.Transparency=1 
		end 
		if chosenObject:IsA("BasePart") then
			local Weld = Instance.new("Weld")
			Weld.Part0 = Clone.Main
			Weld.Part1 = chosenObject
			local CJ = CFrame.new(Clone.Main.Position) 
			Weld.C0 = Clone.Main.CFrame:inverse()*CJ 
			Weld.C1 = chosenObject.CFrame:inverse()*CJ  
			Weld.Parent = Clone.Main
		end
		local Y=Instance.new("Weld")
		y.Part0 = part
		Y.Part1 = Clone.Main 
		Y.C0 = CFrame.new(0, 0, 0)
		Y.Parent = Y.Part0
	end
	local Finish=Clone:GetChildren() 
	for i=1,#Finish do
		Finish[i].Anchored=false
		Finish[i].CanCollide=false
	end
end

Weld("LA",char:FindFirstChild("Left Arm"))
Weld("LL",char:FindFirstChild("Left Leg"))
Weld("RA",char:FindFirstChild("Right Arm"))
Weld("RL",char:FindFirstChild("Right Leg"))
Weld("TS",char:FindFirstChild("Torso"))
Weld("HD",char:FindFirstChild("Head"))

script.Disabled=true

Adding whitespace characters doesn't make your code more efficient! Use tabs/spaces/new lines to help others understand your code! Please!

If you need any extra help, feel free to let me know!

2 comments

0

when i tried it the parts didnt load at all

0

What's the problem? If you can identify the problem -yourself-, I could fix it for you. This isn't a request site, mind you, I was just being nice to spend a half hour of my day improving your (free modeled) script.

This discussion is preserved as it was. New answers, comments, and votes are closed.