Touch event isnt working

hello im currently trying to detect when one part hits another, yet the .touched event isnt working as shown in the video


image

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera

local Viewport = script.Parent.Viewport
local World = Viewport.World
local Pivot = World.Pivot
local Hit = World.Hit
local Visual = Pivot.Visual

local ForceDirectionXIncremint = 0.01

local function UpdateRotation()
	local PartPosition = Pivot.Position
	local ScreenPosition = Camera:WorldToScreenPoint(PartPosition)

	local Direction = Vector2.new(Mouse.X, Mouse.Y) - Vector2.new(ScreenPosition.X, ScreenPosition.Y)

	local Angle = math.atan2(Direction.Y, Direction.X)

	local Degrees = math.deg(Angle) + -90

	Pivot.CFrame = CFrame.new(Pivot.Position) * CFrame.Angles(0, 0, math.rad(-Degrees))
	Hit.Position += Vector3.new(ForceDirectionXIncremint, 0, 0)
end

RunService.RenderStepped:Connect(UpdateRotation)
Visual.Touched:Connect(function(OtherPart)
	print(OtherPart)
end)
3 Likes

Have you checked if CanTouch is true?

1 Like

World models don’t have all the features of Workspace.

For your use case it’s better to use GetPartsInPart or any other spatial query.

1 Like

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