Help with the Touched function

I’m having a problem with the Touched function, it’s not recognizing the npc, I use a similar script in a tool to damage it, but the skills are not working, I really don’t know the reason, I tried for print (Hit) to see the objects that touch and do not paint anything that is part of the Dummy (NPC).

this is my script (located on ServerScriptService)

 local HumanoidsDamaged = {}
 local char = plr.Character;

 rock.Touched:Connect(function(hit)
			local HitedChar = hit.Parent
			local HitedHum = HitedChar:FindFirstChild("Humanoid")
			if not HumanoidsDamaged[HitedChar] then 
				if HitedHum then
					HumanoidsDamaged[HitedChar] = 1
					if HitedChar ~= char and game.Players:FindFirstChild(HitedChar.Name) then
					HitedHum:TakeDamage(TakeDmgPlayer)
					elseif HitedHum:FindFirstChild("GiverEvent") then
					ChangeHealth(plr,HitedHum,TakeDmgDummy)
					end
				end
			end
		end)

(the Npc’s damage is not the same as the player’s so there are two damage variables!)

Screenshot_17
Screenshot_18

1 Like

You want to find the rock.
For example: game.workspace.rock.Touched:Connect(function(hit).
Try that and the touched function should work.
Also make sure to align the end’s better.

Similar to what Mr_bokboy said, you could also put

local rock = script.Parent

and put the script inside the rock.

if i do it all rocks can do damage, in the current script it takes the Humanoid that touched the rock and sets a variable to not damage all the rocks, there is no way to access the Touched through a Part:Clone()? why am I trying to do that.

You might be able to use a ModuleScript, I use them all the time and they can do anything. If you don’t know how to use them, there are plenty of tutorials and even a very helpful page on developer.roblox.com. Once you know how they work, they’re great.

I know how to use it, thank you very much for your idea