I have a morph I am building, which is supposed to include parts which will change transparency, but I need to write a script which makes sure that there is only one 'chest' model which is child to the character in order for it to work properly. I have tried to write a script which is meant to check if there is already a 'chest' model child to the character before continuing with the rest of the script, and it went something like this:
local found = game.Players.Player.Character:FindFirstChild("Chest") local Morph = script.Parent.Parent["Chest"]
if found == false then
function Check(plr)
local ToReturn = true
return ToReturn
end
function GiveMorph(plr) coroutine.resume(coroutine.create(function() if plr.Character:FindFirstChild(Morph.Name) == nil then if Check(plr) == true then wait(0.1) local Cloned = Morph:clone() Cloned.Parent = plr.Character for i, v in pairs(Cloned:GetChildren()) do coroutine.resume(coroutine.create(function() if v:IsA("BasePart") then if v.Name ~= "Middle" then local w = Instance.new("Weld") w.Part0 = Cloned["Middle"] w.Part1 = v w.C0 = w.Part0.CFrame:inverse() * CFrame.new(w.Part1.Position) w.C1 = w.Part1.CFrame:inverse() * CFrame.new(w.Part1.Position) w.Parent = w.Part0 else coroutine.resume(coroutine.create(function() wait(0.1) local w = Instance.new("Weld", plr.Character["Torso"]) w.Part0 = plr.Character["Torso"] w.Part1 = v w.C0 = CFrame.new(0, 0, 0) end)) end end end)) end for i, v in pairs(Cloned:GetChildren()) do coroutine.resume(coroutine.create(function() if v:IsA("BasePart") then v.Anchored = false v.CanCollide = false end end)) end if plr.Character:findFirstChild("Shirt") ~= nil then plr.Character["Shirt"]:remove() end if script.Parent:findFirstChild("Shirt") ~= nil then script.Parent["Shirt"]:clone().Parent = plr.Character end if plr.Character:findFirstChild("Pants") ~= nil then plr.Character["Pants"]:remove() end if script.Parent:findFirstChild("Pants") ~= nil then script.Parent["Pants"]:clone().Parent = plr.Character end for i, v in pairs(plr.Character:GetChildren()) do coroutine.resume(coroutine.create(function() if v:IsA("CharacterMesh") then v:remove() end if v:IsA("Hat") then v:remove() end end)) end end end end)) end
function Touch(hit) coroutine.resume(coroutine.create(function() if hit.Parent:findFirstChild("Humanoid") ~= nil then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr ~= nil then GiveMorph(plr) wait(5) end end end)) end
script.Parent.Touched:connect(Touch)
- note that the very beginning of the script in regards to 'found' and 'if found == false then' are the parts which are supposed to check if the 'chest' part is child to the character. It hasn't worked for me so for, so what am I doing wrong?

2 comments
I am curious where you found out about "pre class" being as it looks like HTML and how you would know whether or not it is compatible with roblox's scripting?
Read my comment on Br4veh3art23's answer. @RockerCaleb1234