I have a morph which I am using for my latest game, but it gives the player more than one of each limb (chest,arms,legs). This interferes with another script which is supposed to change the transparency of some of the parts in the chest. I tried adding a wait into the script at first, but I figured that that would be a poor fix, as if a player runs into the morph a second time, the problem will still stand. I am not sure how to proceed, and any suggestions on where to start or how to go about it would be fantastic. Here is the morph script I am dealing with right now:
local Morph = script.Parent.Parent["Chest"]
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)
end
end
end))
end
script.Parent.Touched:connect(Touch)
--- The morph is a model visible to the players which they are meant to touch.

1 comment
Use a code block, man. The code without a code block is almost unreadable!