Welding parts while dragging and pressing "Z" key, and touching another part

So since maybe 8 hours i am trying to make a script that would weld 2 parts under three conditions: it must touch another part (which must be called Hitbox), the player must press the Z key and must be dragging the part while the two other happen. They must be all true at once for the weld to work.

Here’s the structure:
image
(weldconstraint connects Hitbox and Part)

Values are in ReplicatedStorage.

I’ve tried everything that i could find. Nothing matched my problem.
I hope someone helps. Thanks in advance.

Generally i’ve tried everything. Even AI didn’t help (humongous). Finally i’ve come to the point where i have 2 scripts:

This one gives a value true when player presses Z,
Second one, inside the Model containing the parts, it gets value true when the part touches. However, i think, perchance, that dragging triggers mouseclicks on UserInputService, which changes the previous value to false, since in this script never does “preparing to weld” print:

service = game:GetService("ReplicatedStorage")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Z then
		local playerValue = service:WaitForChild(game.Players.LocalPlayer.Name.."Pressing")
		playerValue.Value = true
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Z then
		local playerValue = service:WaitForChild(game.Players.LocalPlayer.Name.."Pressing")
		playerValue.Value = false
	end
end)```



```local touchPart = nil
local service = game:GetService("ReplicatedStorage")

script.Parent.Hitbox.Touched:Connect(function(touch)
	if touch.Name == "Hitbox" then
		script.Parent.Touching.Value = true
		touchPart = touch
	end
end)

script.Parent.Hitbox.TouchEnded:Connect(function(touch)
	script.Parent.Touching.Value = false
	touchPart = nil
end)

script.Parent.Hitbox.DragDetector.DragContinue:Connect(function(drag)
	script.Parent.Part.Highlight.OutlineTransparency = 0
	script.Parent.Part.Highlight.FillTransparency = 0.5
	local player = drag.Name
	local press = service:WaitForChild(player.."Pressing")
	print(press.Value)
	if script.Parent.Touching.Value == true then
		if press.Value == true then
		print("preparing to weld")
			local weld = Instance.new("WeldConstraint")
			weld.Part0 = script.Parent.Hitbox
			weld.Part1 = touchPart
			weld.Parent = script.Parent.Hitbox
			weld.Enabled = true
		end
	end
end)

script.Parent.Hitbox.DragDetector.DragEnd:Connect(function()
	script.Parent.Part.Highlight.OutlineTransparency = 1
	script.Parent.Part.Highlight.FillTransparency = 1
end)

script.Parent.Hitbox.DragDetector.MouseHoverEnter:Connect(function()
	script.Parent.Part.Highlight.OutlineTransparency = 0
end)

script.Parent.Hitbox.DragDetector.MouseHoverLeave:Connect(function()
	script.Parent.Part.Highlight.OutlineTransparency = 1
end)```
1 Like

Place1.rbxl (61.3 KB)
try this

1 Like

It doesn’t really do anything. I’m further working on this thing, but thanks for help.

1 Like

Okay so finally ive managed to make the weld thingy with right button click. Thanks for help.

tell us how you fixed it. and mark your reply as the solution

I didn’t really fix it, but i found another way to do it. DragDetector also has right mouse button click event, and i used it for the welding.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.