Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Touched is not a valid member of Tool?

Asked by 4 years ago

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)
0
if you mean the handle so use script.Parent.Handle.Touched Mr_m12Ck53 105 — 4y

2 answers

Log in to vote
0
Answered by
ImTrev 344 Moderation Voter
4 years ago

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.

0
I hate to ask for more of an explanation, but I am very lost. JarringJar 0 — 4y
Ad
Log in to vote
0
Answered by
zomspi 541 Moderation Voter
4 years ago

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.

Answer this question