Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can get a morph to work for R6 characters but not people with R15 characters?

Asked by 6 years ago
Edited 6 years ago

I made a morph that uses the two scripts below. However, this morph only works for people with r6 and everyone else that uses the morph in my game only loses a head. Does anybody know if there's any way of fixing this?

Script 1:

function onTouch(part) local humanoidRootPart = part.Parent:findFirstChild("Humanoid") if humanoidRootPart ~= nil then part.Parent:findFirstChild("Head").Transparency = 0.98 part.Parent:findFirstChild("Torso").Transparency = 1 part.Parent:findFirstChild("Left Arm").Transparency = 1 part.Parent:findFirstChild("Right Arm").Transparency = 1 part.Parent:findFirstChild("Left Leg").CanCollide = true part.Parent:findFirstChild("Left Leg").Transparency = 1 part.Parent:findFirstChild("Right Leg").CanCollide = true part.Parent:findFirstChild("Right Leg").Transparency = 1 end end script.Parent.Touched:connect(onTouch)

Script 2:

function onTouched(hit) if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Chest") == nil then local g = script.Parent.Parent.Chest:clone() g.Parent = hit.Parent local C = g:GetChildren() for i=1, #C do if C[i].className == "Part" or "Union" then local W = Instance.new("Weld") W.Part0 = g.Middle W.Part1 = C[i] local CJ = CFrame.new(g.Middle.Position) local C0 = g.Middle.CFrame:inverse()CJ local C1 = C[i].CFrame:inverse()CJ W.C0 = C0 W.C1 = C1 W.Parent = g.Middle end local Y = Instance.new("Weld") Y.Part0 = hit.Parent.Torso Y.Part1 = g.Middle Y.C0 = CFrame.new(0, 0, 0) Y.Parent = Y.Part0 end

    local h = g:GetChildren()
    for i = 1, # h do
        if h[i].className == "Part" or "Union" then
            h[i].Anchored = false
            h[i].CanCollide = false
        end
    end

end

end

script.Parent.Touched:connect(onTouched)

2 answers

Log in to vote
0
Answered by
Kulh 125
6 years ago

The best way to morph for R15 is to changed the characters load value.

But in this case, you need to convert the script to R6 and R15 compatibility.

Ad
Log in to vote
0
Answered by 6 years ago

Following up with what that nice guy said ^. R6 and R15 have different amounts of parts. For limbs, there are three (Example Left Arm in R15: "UpperLeftArm", "LowerLeftArm". "LeftHand")

This is what your script should look like for R15 compatibility:

function onTouch(part) 
local humanoidRootPart = part.Parent:findFirstChild("Humanoid") 
if humanoidRootPart ~= nil then
    part.Parent:findFirstChild("Head").Transparency = 0.98 
    part.Parent:findFirstChild("UpperTorso").Transparency = 1 
    part.Parent:findFirstChild("LowerTorso").Transparency = 1 
        part.Parent:findFirstChild("LeftUpperArm").Transparency = 1 
        part.Parent:findFirstChild("LeftLowerArm").Transparency = 1
        part.Parent:findFirstChild("LeftHand").Transparency = 1
        part.Parent:findFirstChild("RightLowerArm").Transparency = 1 
        part.Parent:findFirstChild("RightUpperArm").Transparency = 1
        part.Parent:findFirstChild("RightHand").Transparency = 1
            part.Parent:findFirstChild("LeftUpperLeg").CanCollide = true 
            part.Parent:findFirstChild("LeftUpperLeg").Transparency = 1 
            part.Parent:findFirstChild("LeftLowerLeg").CanCollide = true 
            part.Parent:findFirstChild("LeftLowerLeg").Transparency = 1 
            part.Parent:findFirstChild("LeftFoot").CanCollide = true 
            part.Parent:findFirstChild("LeftFoot").Transparency = 1 
                part.Parent:findFirstChild("RightUpperLeg").CanCollide = true 
                part.Parent:findFirstChild("RightUpperLeg").Transparency = 1 
                part.Parent:findFirstChild("RightLowerLeg").CanCollide = true 
                part.Parent:findFirstChild("RightLowerLeg").Transparency = 1 
                part.Parent:findFirstChild("RightFoot").CanCollide = true 
                part.Parent:findFirstChild("RightFoot").Transparency = 1 
end 
end 
    script.Parent.Touched:connect(onTouch)

Alternatively, instead of using that large block, you can use something way more simple like i,v in pairs to iterate thru the characters parts, and if its part is a limb, do that:

    function onTouch(part) 
        for i,v in pairs(part.Parent:GetChildren()) do -- Define where the character is after pairs, this will get all the children of the players character
        if v:IsA("MeshPart") then -- Checks if the part its focused on is a body part, not an accessory, clothing item, etc
            v.CanCollide = true -- if its a body part, set it to can collide, and set its transparency
            v.Transparency = 1
        elseif v.Name == "Head" then -- I noticed you had head set to 0.98, so it checks if the part is called head, then changes it too
            v.Transparency = 0.98
        end
    end 
    end
    script.Parent.Touched:connect(onTouch)

Answer this question