The .Touched function does NOT want to interact with the enviorment

I have been cracking my head at this for like 3 hours. So, i am making a pvp-like game and i want to make it so whenever this “Mic” part touches anything it stops its flight early and falls down but if its a player then it also deals 10 damage, but it has been a nightmare to code, the only things it seems to interact with is: the baseplate, rigs (with its humanoidrootpart unanchored and only if it is unanchored for some reason) and thats it. While it SHOULD interact with things such as props and well, rigs with humanoidrootparts anchored. Heres a list of all things i tried to do:

  1. I tried checking if the parts had cantouch off, they did not.

  2. I tried using prints to find out where it goes wrong for some reason the .Touched function doesnt even want to trigger itself if it is not colliding with a player or a baseplate

Here’s the video of it in action:

The ServerScriptService code:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local atkDb = false
local atkReady = true

local Event = game.ReplicatedStorage.TossMic -- Path to Remote Event
Event.OnServerEvent:Connect(function(Player)
	if atkReady == true then
		atkReady = false
		local character = Player.Character
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
		local block = ReplicatedStorage:WaitForChild("Mic"):Clone()
		
		block.Parent = workspace
		block:PivotTo(humanoidRootPart.CFrame * CFrame.new(0,0,-3))
		block.Orientation = humanoidRootPart.Orientation
		block.Throw:Play()

		local moveDirection = humanoidRootPart.CFrame.LookVector
		local moveSpeed = 30
		local spinSpeed = -10

		block.Touched:Connect(function(hit)
			print("Touched!")
			if hit.Parent:FindFirstChild("Humanoid") then
				local humanoid = hit.Parent.Humanoid
				if humanoid.Parent.Name ~= Player.Name and atkDb == false then
					atkDb = true
					block.Hit:Play()
					hit.Parent.Humanoid:TakeDamage(10)
					moveSpeed = 0
					spinSpeed = 0
					block.CanTouch = false
					block.CanQuery = false
					block.CanCollide = true
					block.Anchored = false
				end
			else
				print("Touched a non player!")
				moveSpeed = 0
				block.CanCollide = true
				block.Anchored = false
			end
		end)

		RunService.Heartbeat:Connect(function(dt)
			block.CFrame = (block.CFrame + moveDirection * moveSpeed * dt) * CFrame.fromEulerAngles(math.rad(spinSpeed), 0, 0)
		end)

		task.wait(1.2)

		block.CanCollide = true
		block.Anchored = false

		wait(0.4)
		block:Destroy()
		atkDb = false
		task.wait(1)
		atkReady = true
	end
end)

am i missing some obvious mistake?

The Touched event only works on Unanchored parts. Weather it be the Tree or the Microphone. It’s completely run by Physics.

Instead, you can use GetPartsInPart to retrieve a list of intersecting or colliding parts of the hitbox.

You can set OverlapParams as a filter. I would suggest setting the MaxParts variable to 1, so you can just use it like this.

local params = OverlapParams.new() -- Filter, similar to RaycastFilter
params.MaxParts = 1

while task.wait() do -- while loop lol
    local Part = Workspace:GetPartsInPart(workspace.Rizz, params)[1] -- Get the first touched part
    print(Part) -- Prints the first part that touched it.
end

I would use Heartbeat or stepped to perform the loop for better performance. Don’t forget to use :Disconnect() after the loop needs to be stopped.

local coolguy = game:GetService("RunService").Heartbeat:Connect(function() -- Create our Disconnectable loop
    print("I AM ALIVE!")
end)

task.wait(5) -- Wait 5 seconds, obviously.

coolguy:Disconnect() -- Breaks the loop and ends it
1 Like