The issue I am dealing with is that I cant figure out how to filter out everything BUT the couplers itself since the touch affects everything. I have been drawing blanks, cant find anything useful at all to help nor will anything work for this. Regardless of any checks I have made it still interacts with everything and introducing “Else” makes it automatically go to else no matter what/
local TouchPart = script.Parent
local Clicker = script.Parent.ClickDetector
local Attachment = script.Parent.CouplerAttach
TouchPart.Touched:Connect(function(coupling)
if script.Parent.IsCoupled.Value == false then
TouchPart.IsCoupled.Value = true
script.Parent.IsCoupled.Value = true
local Rope = Instance.new("RopeConstraint")
Rope.Parent = TouchPart
Rope.Length = 2
Rope.Visible = true
Rope.Attachment0 = TouchPart.CouplerAttach
Rope.Attachment1 = coupling.CouplerAttach
print "been touched"
end
end)
Clicker.MouseClick:Connect(function(Decouple)
if IsCouple == true then
local Rope = TouchPart:FindFirstChild("RopeConstraint")
if Rope then
Rope:Destroy()
IsCouple = false
TouchPart.Value = "0"
print "is destroyed"
end
end
end)
I would like for the two couplers to touch and then connect, then be destroyed once clicked. I know I need a debounce but right now I just cannot get this to work for the life of me. I dont need anything fancy, just trying to make a simple train coupler.
If anything right now. It interacts with everything and changes the IsCoupled state effectively breaking the model.
I would recommend checking that the touching part is actually another coupler. Based on your screenshot of the explorer, you can check if the attachment exists:
TouchPart.Touched:Connect(function(coupling)
if not coupling:FindFirstChild("CouplerAttach") then
return
end
if script.Parent.IsCoupled.Value == false then
TouchPart.IsCoupled.Value = true
script.Parent.IsCoupled.Value = true
...
local TouchPart = script.Parent
local Clicker = script.Parent.ClickDetector
local Attachment = script.Parent.CouplerAttach
TouchPart.Touched:Connect(function(coupling)
if not coupling:FindFirstChild("CouplerAttach") then
print("coupler not found")
return
end
if script.Parent.IsCoupled.Value == false then
script.Parent.IsCoupled.Value = true
print("coupler found")
local Rope = Instance.new("RopeConstraint")
Rope.Parent = script.Parent
Rope.Visible = true
Rope.Length = 2
Rope.Attachment0 = script.Parent.CouplerAttach
Rope.Attachment1 = coupling.CouplerAttach
end
end)
TouchPart.ClickDetector.MouseClick:Connect(function(clicked)
if not clicked:FindFirstChild("RopeConstraint") then
print("rope not found")
return
end
if script.Parent.IsCoupled.Value == true then
script.Parent.Rope:Destroy()
end
end)
The thing given by ClickDetector.MouseClick is the player, NOT the object. Try replacing clicked with TouchPart within the code, and the parameter given in the function(clicked) to player