Player = script.Parent.Parent c = Player.Character Sword = Instance.new("Part") Sword.Parent = c SwordMesh = Instance.new("SpecialMesh") SwordMesh.MeshId = "rbxassetid://432068544" SwordMesh.Parent = Sword Sword.CanCollide = false w1 = Instance.new("Weld", c) w1.Part0 = w1.Parent["Right Arm"] w1.Part1 = Sword w1.C1 = CFrame.fromEulerAnglesXYZ(1.5,0,1.4) *CFrame.new(0,1.2,2) function onSliced(Sword) if Sword:FindFirstChild("Torso") then Sword.Humanoid.Health = Sword.Humanoid.Health -5.5 print("Hit") end end Sword.Touched:connect(onSliced) --What am I doing wrong When sword touches a torso it should be doing damage but its not..
What is happening is the Touched event provides the part that touched the brick you connected the event to. So on line 14, you're redefining the Sword, when in reality it's the part that is hitting it.
Another issue is you're assuming whatever the sword is hitting is a character. If a part in workspace or in the model you're hitting so happens to have the name Torso, then your script will error.
There may also be that possibility that the sword holder is the person who hit the sword. You can avoid this by making sure that the sword holder is not the thing that hits it.
On line 14, change Sword to something else. Let's say Target.
We'll also look for Humanoid rather than Torso, and we'll need to check Target's parent for the Humanoid.
If the script were a LocalScript, I do not see why you wouldn't use LocalPlayer. However, since you're code is defining player as script.Parent.Parent I will assume you're using a server script. We'll need to identify if the parent of the part being hit is the player or not. We'll want to get the GetPlayerFromCharacter function and compare it with the player variable.
Player = script.Parent.Parent c = Player.Character Sword = Instance.new("Part") Sword.Parent = c SwordMesh = Instance.new("SpecialMesh") SwordMesh.MeshId = "rbxassetid://432068544" SwordMesh.Parent = Sword Sword.CanCollide = false w1 = Instance.new("Weld", c) w1.Part0 = w1.Parent["Right Arm"] w1.Part1 = Sword w1.C1 = CFrame.fromEulerAnglesXYZ(1.5,0,1.4) *CFrame.new(0,1.2,2) function onSliced(Target) --Changed the variable. if Target.Parent:FindFirstChild("Humanoid") then --Locating Humanoid. if game.Players:GetPlayerFromCharacter(Target.Parent) ~= Player then --Now that we confirmed it was a character model, compare it to if the player is the target. Sword.Humanoid.Health = Sword.Humanoid.Health - 5.5 --Reduce health. ForceFields will not respect this method. I would recommend using function TakeDamage(). print("Hit") end end end Sword.Touched:connect(onSliced)