Problems with touched event

Hello devs!, I’m currently trying to achieve a pipe puzzle, which player can rotate pipe to power up an gate, however, my hitbox parts just don’t work, they’re are unanchored and rigged to the pipe. I know what it could be, CFrame moving! I use CFrame tween to rotate pipe.

I just want a way to still rotate pipes by tween. And firing the Touched event

Here’s some screenshoot of my work:

Captura de tela 2025-01-18 160652

Here’s the rotate script:

local possibleRotations = {
	90,
	180,
}

local debounce = false
local number = math.random(1,2)
script.Parent.Parent.Orientation =  Vector3.new(0,0,table.find(possibleRotations,number))
local tween = game:GetService("TweenService")
local info = TweenInfo.new(0.5, Enum.EasingStyle.Linear)
script.Parent.MouseClick:Connect(function()
	if debounce == false then
		debounce = true
		local tween1 = tween:Create(script.Parent.Parent, info, {Orientation = script.Parent.Parent.Orientation + Vector3.new(0,0,90)})
		tween1:Play()
		tween1.Completed:Connect(function()
			task.wait(.1)
			debounce = false
		end)
		
	end

end)

Here’s the script of the hitbox:

script.Parent.Touched:Connect(function(hit)
	print("Started")
	print(hit.Parent.Name)
	if hit.Name == "HitBox" then

		if hit.Parent:FindFirstChild("Straight").Powered.Value == true or hit.Parent:FindFirstChild("Curve").Powered.Value == true then
			script.Parent.Parent.Straight.Powered.Value = true
		end
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	print("Ended")
	if hit.Name == "HitBox" then
		if script.Parent.Parent.Straight.Powered.Value == true then
			script.Parent.Parent.Straight.Powered.Value = false
		end
	end
end)


1 Like

Ignore active windows. I haven’t actived it until now :sweat_smile:

1 Like