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

My constraints are not working how I want them to. Anyone have any ideas?

Asked by 6 years ago

I'm using a RopeConstraint as handcuffs so when you click on a player with the handcuffs, you can jail them and pull them wherever you would like. However it gets glitchy and the jailed person can actually move by pulling the handcuff holder when he's not moving. I've tried attaching the constraints to the HumanoidRootPart, Legs, Arms, Torso and even the tool itself but none of them solve this problem. Its filtering enabled compatible currently. And if anyone knows how to solve the problem with me still being able to use the tool once I've unequipped it for the first time, please let me know.

**-- Local Script**

Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
debounce = false

anim = game.ReplicatedStorage.Caught

script.Parent.Equipped:Connect(function()
    mouse.Button1Down:Connect(function()
        if mouse.Target ~= nil then
            local Hit = mouse.Target
            print("hi")
                if Hit.Name == ("Torso") or Hit.Name == ("Head") or Hit.Name == ("Left Leg") or Hit.Name == ("Right Leg") or Hit.Name == ("HumanoidRootPart") or Hit.Name == ("Left Arm") or Hit.Name == ("Right Arm") then
                    print("hi")
                    local Jailed = Hit.Parent
                    local Jailed2 = Jailed:FindFirstChild("HumanoidRootPart")
                    local Jailed1 = Player.Character.Tool.Handle
                    script.Parent.RemoteEvent:FireServer(mouse,anim,Jailed,Jailed2,Jailed1,Hit)
        end     end
end) end)

**-- Script**

script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player,mouse,anim,Jailed,Jailed2,Jailed1,Hit)
    print("hi")
    local attachmentB = Instance.new("Attachment",Jailed2)
    local attachmentA = Instance.new("Attachment",Jailed1)
    attachmentA.Position = Vector3.new(1,-0.7,0.3)
    attachmentB.Position = Vector3.new(0,0,0.3)

    print("hi")
    local ropeConstraint = Instance.new("RopeConstraint",Jailed1)
    ropeConstraint.Attachment0 = attachmentA
    ropeConstraint.Attachment1 = attachmentB
    ropeConstraint.Length = 10
    ropeConstraint.Visible = true
    ropeConstraint.Color = BrickColor.Black()
    ropeConstraint.Thickness = 0.2
    ropeConstraint.Restitution = 0.5
    Jailed.Humanoid.Walkspeed = 0
    local caught = Jailed.Humanoid:LoadAnimation(anim)
    caught:Play()


    script.Parent.Unequipped:Connect(function() 
        ropeConstraint:Destroy()
        caught:Stop()
        Jailed.Humanoid.Walkspeed
    end)

end)
0
That can get pretty complex it would seem. I'd just write it from scratch and have the person who's handcuffed move when the captor moves (given that they're at the distance limit) Pejorem 164 — 6y
0
I would prefer the captive to also be able to move around when the captor isn't ThePhantomG 30 — 6y
0
In my example they would be able to Pejorem 164 — 6y
0
Well, thats kinda realistic to have the criminal be able to move handcuffs. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Create an invisible, anchored, non-collidable Part that is continuously updated to have its Position equal to the torso of the one holding the handcuffs.

The reason you can still use the tool after unequipping is because you never destroy the connection you made to mouse.Button1Down.

--Near top
local con

--Line 10:
con = mouse.Button1Down:Connect(function()

--At end of LocalScript:
script.Parent.Unequipped:Connect(function()
    if con then
        con:Disconnect()
        con = nil
    end
end)

Also, you shouldn't connect to events within other events (server-script, line 46) -- you'll end up making more than one connection over time. Instead, use a boolean variable, like this:

local isCaught = false
local ropeConstraint, caught, jailed
function CaughtDone()
    if isCaught then
        ropeConstraint:Destroy()
            caught:Stop()
            jailed.Humanoid.Walkspeed = 15 -- or whatever
    end
    isCaught = false
end

--At the beginning of the RemoteEvent:
    CaughtDone() -- clean up any previous handcuffing

--Right after "caught:Play()":
    isCaught = true
    jailed = Jailed -- store who is Jailed in the 'jailed' variable so that 'CaughtDone' has access to it

--Delete the script.Parent.Unequipped block

--At the end of the script:
script.Parent.Unequipped:Connect(CaughtDone)
0
Where do I put the local "isCaught" to the "isCaught = false" bit? ThePhantomG 30 — 6y
0
In the 2nd script, lines 1-10 are to go at the beginning of your server-script. chess123mate 5873 — 6y
Ad

Answer this question