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)

1 comment
if you mean the handle so use script.Parent.Handle.Touched