Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Touched is not a valid member of Tool?

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

0

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

2 answers

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.

1 comment

0

I hate to ask for more of an explanation, but I am very lost.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.