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

Rope Constraints not working properly?

Asked by 7 years ago

I'm trying to make a tool that shoots "webs" but the Rope Constraint is not appearing. The idea is that one projectile is shot out first then the second projectile is shot, the two projectiles connect with each other with the Rope Constraint making it look like a "web". The attachment property of the Rope Constraint Is the part where the problem occurs

tool = script.Parent
WebBall = Instance.new("Part")
WebBall.Size = Vector3.new(1,1,1)
WebBall.TopSurface = Enum.SurfaceType.Smooth
WebBall.BottomSurface = Enum.SurfaceType.Smooth
WebBall.Shape = "Ball"
WebBall.CanCollide = true

local stat = 0
local stats = 0
function shoot(v)
    stat = stat + 1
    local bullet = WebBall:Clone()
    local bullet2 = WebBall:Clone()
    local attach = Instance.new("Attachment")
    attach.Parent = bullet
    attach.Name = "HookStart"
    local attach2 = Instance.new("Attachment")
    attach2.Parent = bullet2
    attach2.Name = "HookEnd" 
    if stat == 1 then

        bullet.Name = " Hook1"

        local Character = tool.Parent
        local Head = Character:FindFirstChild("Head")
        bullet.Parent = workspace
        local launch = Head.Position + 10 * v
        bullet.CFrame = CFrame.new( launch, launch + v)
        bullet.Velocity = v * 100
        local bool = false
        bullet.Touched:connect(function(hit)
            if hit and bool == false then
                bool = true
                local weld = Instance.new("Weld")
                weld.Parent = bullet
                weld.Part0 = bullet
                weld.Part1 = hit
                local bulletPos = bullet.Position
                local Joint = CFrame.new(bulletPos)
                local C0 = bullet.CFrame:inverse() * Joint
                local C1 = hit.CFrame:inverse() * Joint
                weld.C0 = C0
                weld.C1 = C1
                wait()


            end
        end)
    end 
    if stat == 2 then

        print("here")
        bullet2.Name = "Hook2"


        local Character = tool.Parent
        local Head = Character:FindFirstChild("Head")
        bullet2.Parent = workspace
        local launch = Head.Position + 10 * v
        bullet2.CFrame = CFrame.new( launch, launch + v)
        bullet2.Velocity = v * 100
        local bool = false
        bullet2.Touched:connect(function(hit)

            if hit and bool == false then

                local rope = Instance.new("RopeConstraint")
                rope.Parent = bullet2
                rope.Visible = true
                rope.Thickness = 0.5
                rope.Color = BrickColor.White()

                local dis = (bullet.Position - bullet2.Position).magnitude
                rope.Length = dis - 0.3

                rope.Attachment1 = bullet2:WaitForChild("HookEnd")-- This also.
                wait()
                rope.Attachment0 = bullet:WaitForChild("HookStart") -- This is the problem.

                bool = true

                local weld = Instance.new("Weld")
                weld.Parent = bullet2
                weld.Part0 = bullet2
                weld.Part1 = hit
                local bulletPos = bullet2.Position
                local Joint = CFrame.new(bulletPos)
                local C0 = bullet.CFrame:inverse() * Joint
                local C1 = hit.CFrame:inverse() * Joint
                weld.C0 = C0
                weld.C1 = C1

                print(dis)
                wait()
                stat = 0
            end
        end)
    end
end

function fire()
    local Character = tool.Parent
    local Humanoid = Character:FindFirstChild("Humanoid")
    local look = (Humanoid.TargetPoint - Character:FindFirstChild("Head").Position).unit
    shoot(look)
end
script.Parent.Activated:connect(fire)

Answer this question