Making a Sword Not Damage Players!

  1. What do you want to achieve? Keep it simple and clear!
    Hello, I am simply trying to make a weapon which cannot harm other players only NPCs

  2. What is the issue? Include screenshots / videos if possible!
    The Main issue right now is I have no clue what I am doing and am unsure what to do.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tryed to search for similar stuff on the Devforum but I cant find anything really related to my
    issue.

Below is the code I have, I did follow a Tutorial for this. I have a script inside the tool called Sword and one inside that called Damage. Thank you for any help.

local animations = {"8827622082";"8827622891";"8827624312";"8827625666"}
local tool = script.Parent
local enabled = true
local char

tool.Activated:connect(function()
	if enabled then
		enabled = false
		local char = tool.Parent
		local random = animations[math.random(1,#animations)]

		local anim = Instance.new("Animation")
		anim.AnimationId = "http://www.roblox.com/asset/?id="..random

		local track = char.Humanoid:LoadAnimation(anim)
		track:Play()

		local damage = script.Damage:Clone()
		damage.Parent = tool.Blade
		damage.Disabled = false
		wait(track.Length)

		enabled = true
		if damage then
			damage:Destroy()
		end
	end
end)
-- Damage
local weapon = script.Parent
local dmg = math.random(300,500) 

weapon.Touched:connect(function(part)
	if part.Parent:findFirstChild("Humanoid") then
		local humanoid = part.Parent:findFirstChild("Humanoid")
		humanoid:TakeDamage(dmg)
		script:Destroy()
	end
end)
2 Likes

Make this check game.Players:GetPlayerFromCharacter(char)

1 Like

You can change the NPC’s humanoid name and use npcModel:FindFirstChild(“NPC”)…

1 Like