Why is my skill not damaging the npc unless my player is touching the npc

I am using a local script in a tool to determine the location of my mouse, then create a copy of a part in replicated storage.

When I test this and put make NewLN go to mouse position tit does nothing to the dummy humanoid when touching, however when i touch the dummy with my player and do it somehow it worked. I want it to make damage on its own.

here is my script:

tool = script.Parent 

local ip = game:GetService("Players").LocalPlayer
local ui = game:GetService("UserInputService")
local db = false
local cd = 1
local EQ = false
local dmg = 10
local RS = game:GetService("ReplicatedStorage")
local LN = RS:WaitForChild("Lightning")
local player = game:GetService("Players").LocalPlayer
local desired desiredPosition = nil

tool.Equipped:Connect(function()
	 EQ = true
end)

tool.Unequipped:Connect(function()
	EQ = false
end)

ui.InputBegan:Connect(function(type1,typing)
	if typing then
		return
	elseif type1.KeyCode == Enum.KeyCode.Q and db == false and EQ == true then
		db = true
		
		local mouse = game.Players.LocalPlayer:GetMouse()
		local char = player.Character
		
		
		local NewLN = LN:Clone()
		NewLN.CFrame = CFrame.new(mouse.Hit.Position.X,0, mouse.Hit.Position.Z)
		NewLN.Parent = game.Workspace
		
		
		NewLN.Touched:Connect(function(hit)
			print("hi")
		
			local hum = hit.Parent:FindFirstChild("Humanoid")
			if hum and hum ~= char.Humanoid then
				print("humfound")
				hum:TakeDamage(dmg)	
			end
		end)
  
		wait(1)
		NewLN:Destroy()
	wait(cd)
		db = false
	end
end)

pls help

Your script works for me.

Added the last 3 lines of code:

		db =false
	end
end)

Is your part in Replicated Storage set to CanTouch?

no it is not set to can touch, is that important?

It shows but it doesnt damage the npc, does it do that for you?

I used a part named Lightning with your script.

It was set to CanTouch.

When I placed my mouse over the other character and pressed Q.

The part from storage appeared and damaged their character.

Huh that only works for me if the part is unanchored and non collided off so that the part or dummy moves or else it doesn’t do anything

I’m pretty sure you need to enable CanTouch for touched events to fire.

Also if you plan to damage the NPC using LocalScript, I don’t think it’ll work if you have set the NPC model network connection to the server.

What do you mean by network connection?

I think they meant to say “network ownership”, but essentially if you damage the NPC using a LocalScript that damage will only be applied for that LocalScript’s player and the NPC will stay unharmed for everyone else. To solve this problem you’ll need to use a RemoteEvent to send a signal to the server when you want to damage the NPC and damage it within the server Script that has the OnServerEvent connection for the RemoteEvent

uhh ok, im still not so sure how that works, but ill look at the links u sent for advice so thanks

1 Like

Yeah I meant to say network ownership, mb.