Good evening! I am attempting to add 'Touched' onto my sword to give it the capability of damaging other players and NPCs. However, upon running the test, the error message stated in the title appears. Any help is much appreciated. This is all from the LocalScript.
local replicatedStorage = game:GetService("ReplicatedStorage") local remoteData = game:GetService("ServerStorage") local cooldown = 2 script.Parent.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function() local Track = Instance.new("Animation") Track.AnimationId = "rbxassetid://4929040648" local player = game:GetService("Players").LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local canplay = true script.Parent.Activated:Connect(function() local animation = char:WaitForChild("Humanoid"):LoadAnimation(Track) if canplay == true then Track:Play() canplay = false wait(1) Track:Stop() canplay = true end end) local module = require(script.Parent:WaitForChild("ModuleScript")) local player = game.Players.LocalPlayer script.Parent.Activated:Connect(function() module.Swing() end) end) end) local canattack = true script.Parent.Touched:Connect(function(p) local humanoid = p.Parent:FindFirstChild("Humanoid") if canattack == true and humanoid then canattack = false humanoid:TakeDamage(20) end end)
Script.Parent seems to be a tool, and you can't connect touched with tools. You need to put the changed event on a part in the tool itself.If you need more of an explanation, just ask.
You can't use Touched events on tools, only on parts. If you are making a sword you should probably have a blade. Instead of detecting when something touches the tool, detect when it touches the blade of your sword, as the blade is a part, generally the blade is an invisible part that covers the blade of your sword. You can use any part though, just often using a transparent 'blade' is easier as swords often contain many meshes and parts.