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

UnionOperation not working in moprh?

Asked by 7 years ago

I am trying to create a morph where you touch a button and belt morphs on you. I have tried to do this on my own but have failed miserably.

The button contains several scripts: Arms, Legs, PresentScript, Script, Torso

Before added this

if C[i].className == "UnionOperation" 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

The script worked but only gave me the morph that isn't a union. After when I added it the whole morph did not work. When I tested the morph with this my output stated:

Workspace.PoliceDutyBelt.Button.Legs:85: 'end' expected (to close 'if' at line 2) near '<eof>'

Workspace.PoliceDutyBelt.Button.Arms:85: 'end' expected (to close 'if' at line 2) near '<eof>'

Workspace.PoliceDutyBelt.Button.Torso:44: 'end' expected (to close 'function' at line 1) near '<eof>'

When I touched the part it said: Delete is not a valid member of Part

Arms Script:

function onTouched(hit)
    if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Arm1") == nil then
        local g = script.Parent.Parent.Arm1:clone()
        g.Parent = hit.Parent
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" 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
            if C[i].className == "UnionOperation" 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["Left Arm"]
                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
            h[i].Anchored = false
            h[i].CanCollide = false
        end

    end

    if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Arm2") == nil then
        local g = script.Parent.Parent.Arm2:clone()
        g.Parent = hit.Parent
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" 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
            if C[i].className == "UnionOperation" 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["Right Arm"]
                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
            h[i].Anchored = false
            h[i].CanCollide = false
        end

    end
end

script.Parent.Touched:connect(onTouched)

Legs Script:

function onTouched(hit)
    if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Leg1") == nil then
        local g = script.Parent.Parent.Leg1:clone()
        g.Parent = hit.Parent
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" 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
            if C[i].className == "UnionOperation" 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["Left Leg"]
                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
            h[i].Anchored = false
            h[i].CanCollide = false
        end

    end

    if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Leg2") == nil then
        local g = script.Parent.Parent.Leg2:clone()
        g.Parent = hit.Parent
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" 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
            if C[i].className == "UnionOperation" 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["Right Leg"]
                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
            h[i].Anchored = false
            h[i].CanCollide = false
        end

    end
end

script.Parent.Touched:connect(onTouched)

PresentScript Script:

local debounce = false

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 

function onTouch(part) 

local human = part.Parent:findFirstChild("Humanoid") 
if (human ~= nil) and debounce == false then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

script.Parent.Delete:clone().Parent = player.Backpack
script.Parent.Grab:clone().Parent = player.Backpack
script.Parent.Copy:clone().Parent = player.Backpack
script.Parent.Rotate:clone().Parent = player.Backpack
script.Parent.Resize:clone().Parent = player.Backpack

wait(2)
debounce = false
end
end


script.Parent.Touched:connect(onTouch) 

Script Script:

function onTouched(part)
 local h = part.Parent.Parent:findFirstChild("Humanoid") 
 if (h ~=nil) then -- If there is a Humanoid then
       h.MaxHealth = 120
       h.Health = 120
 end
 end

script.Parent.Touched:connect(onTouched)


Torso Script:

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" 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
            if C[i].className == "UnionOperation" 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
            h[i].Anchored = false
            h[i].CanCollide = false
        end

    end
end

script.Parent.Touched:connect(onTouched)

Please me help, thank you!

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Your problem was just a little format error. All you needed to do was change any second if's to 'elseif' and then add 'end'. Try using this format as a diagram of what I am talking about:

if value == 3 then 
--function
elseif value == 2 then
--function
else
--function
end 
0
I have found another answer and fixed it. I added or "Union" next to if C[i].className == "Part" PvPNinjaDragon 35 — 7y
Ad

Answer this question