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:
(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)```