Hey, I am trying to make a fuel truck for a group I am in. I am trying to make it so a RopeConstraint spawns between 2 click detectors lets say if I clicked click detector one and then click detector 2, it would generate the rope. I will add screenshots to what I am using currently.
You need 2 different attachments then set attachment 0,1 based on what attachments you chose
This isn’t too terribly difficult, you can obviously make the method I am about to show you more complex by adding raycasting to track the exact position of the click and adjusting the attachment as well as other things.
I’ll attach an rbxm file at the bottom so if you are having trouble following my “mini-tutorial”, you can download that and have a look.
First let’s make a folder and call it “Ports”.
Lets add a part into this folder, the size doesn’t matter but for this example I’ll make it a 4x4x4 cube.
Insert an attachment into this cube, and then move it to the front side of the cube (the side you want the rope to connect to).
Let’s also add a click detector, that’ll come in handy a bit later.
Now, duplicate this part, move it away from the original, and reposition the attachment on this clone.
Lets name one of these two parts “Anchor”, we can leave the other one named “Part”.
Now, let’s add a RopeConstraint and a Script to the Ports folder, make sure you enable the RopeConstraint’s visible property.
Open up the script and let’s begin writing!
Let’s first create a variable for the Rope, set the Rope’s Attachment0 to the Anchor part’s attachment, and then start up a generic for loop.
local rope = script.Parent.RopeConstraint
rope.Attachment0 = script.Parent.Anchor.Attachment
for _,part in pairs(script.Parent:GetChildren()) do
end
Let’s also be sure to write in a basic sanity check to make sure the “part” variable is actually a part that has a ClickDetector.
local rope = script.Parent.RopeConstraint
rope.Attachment0 = script.Parent.Anchor.Attachment
for _,part in pairs(script.Parent:GetChildren()) do
if part:IsA("Part") and part:FindFirstChild("ClickDetector") then
end
end
Now that we know the part has a ClickDetector, we can connect to it and have it set the rope’s Attachment1 like so:
local rope = script.Parent.RopeConstraint
rope.Attachment0 = script.Parent.Anchor.Attachment
for _,part in pairs(script.Parent:GetChildren()) do
if part:IsA("Part") and part:FindFirstChild("ClickDetector") then
part.ClickDetector.MouseClick:Connect(function()
rope.Attachment1 = part.Attachment
end)
end
end
Let’s add one last thing, making sure that if the part that is clicked already has a rope attached to it, the rope will detach.
local rope = script.Parent.RopeConstraint
rope.Attachment0 = script.Parent.Anchor.Attachment
for _,part in pairs(script.Parent:GetChildren()) do
if part:IsA("Part") and part:FindFirstChild("ClickDetector") then
part.ClickDetector.MouseClick:Connect(function()
if rope.Attachment1 == part.Attachment then
rope.Attachment1 = nil
else
rope.Attachment1 = part.Attachment
end
end)
end
end
And there we go, a working script!
Rope.rbxm (4.5 KB)
Ok, I think I see how it works now. My problem is that I have multiple jets and I am trying to use 1 fuel truck that would work for all, for instance if I clicked the fuel port on FuelTruck and then the fuel port on VulcanBomber it would attatch a rope between the 2 instead of seperate fuel trucks for seperate aircraft or if there was multiple of the one aircraft.
Funny though, that I already made fuel truck that you can click on it and it connects rope from fuel pump to nearest plane. My tip for you is to search for nearest attachment between planes and the fuel truck that player clicked on.