[Touched is not a valid member of Folder] problem

I created a magic wand that shoots spells but the spell-damage script keeps giving me an error [Touched is not a valid member of Folder] do you have any suggestions for what I could do.

I will link the script if you want to see it.

2 Likes

The Touched event is an event only for BasePart, not folders. If you want, you can make a part, weld it, name it to “TouchPart”, then script the part with the Touched event. This is just an example, but you can improve it further.

I think I already did because: The script is getting cloned into an effect part that holds both the velocity part but also an effect and the damage script.

Can you show me the Explorer to where the wand is and the script?

Sure

Is it good enough?

1 Like

How about the script of the tool?

?
What do you mean?
textlimit textlimit

I need to look at the script you made.

Ok

Wand script:
----------------------------
---------VALUES-------------

local Tool = script.Parent
local isKeyDown = {}
mouse = game.Players.LocalPlayer:GetMouse()
--------ANIMATIONS----------
local WandEquipped = nil
local WandCasting = nil

WandEnabled = false
Casting = false
LumosSP = false

-------CASTING SPELLS-------

function activated()

------------ROLE PLAY SPELLS--------------------

if script.Values.Roleplay.Value == true then
if script.Values.SpellValue.Value == 2 then
Lumos()
elseif script.Values.SpellValue.Value == 3 then
Nox()
else return end end

if Casting == true then return end


if script.Values.SpellValue.Value == 0 then

Protego()

elseif script.Values.SpellValue.Value == 1 then

Episkey()

elseif script.Values.SpellValue.Value == 2 then

Lumos()

elseif script.Values.SpellValue.Value == 3 then

Nox()

elseif script.Values.SpellValue.Value == 4 then

Expelliarmus()

elseif script.Values.SpellValue.Value == 5 then

Rictusempra()

elseif script.Values.SpellValue.Value == 6 then

Stupefy()

elseif script.Values.SpellValue.Value == 7 then

Levicorpus()

end
end

-----------------------EQUIPPED/UNEQUPPED------------------------

function onEquippedLocal(mouse)
local SPGUI = script.GUIs.SpellGui:Clone()
SPGUI.Parent = game.Players.LocalPlayer.PlayerGui
WandEnabled = true

WandEquipped = Tool.Parent.Humanoid:LoadAnimation(script.Animations.WandHold)
WandCasting = Tool.Parent.Humanoid:LoadAnimation(script.Animations.WandCast)

WandEquipped:Play()
mouse.Button1Down:connect(activated)
script.Values.WandOwner.Value = game.Players.LocalPlayer.Name
wait()
game.Players.LocalPlayer.PlayerGui:FindFirstChild(“SpellGui”).Frame.Display.Text = script.Values.SpellValue.SpellName.Value
end

function onUnequippedLocal()
WandEnabled = false
WandEquipped:Stop()
WandEquipped:remove()
WandEquipped = nil
game.Players.LocalPlayer.PlayerGui:FindFirstChild(“SpellGui”):remove()
if game.Players.LocalPlayer.Character:FindFirstChild(“Protego”) ~= nil then game.Players.LocalPlayer.Character:FindFirstChild(“Protego”):remove() else
if LumosSP == true then
script.Parent.Lumos.Transparency = 1
script.Parent.Handle.Lumos.Enabled = false
LumosSP = false else
end
end
end

-------------------------HOT-KEYS--------------------------------

function onKeyDown(key)
if script.Values.SpellBook.Value == true then return end
if WandEnabled == true then
if (not key) then return end
key = string.lower(key)
isKeyDown[key] = true
if (key == “e”) then

script.Values.SpellValue.Value = script.Values.SpellValue.Value+1
if script.Values.SpellValue.Value > script.Values.MaxSpells.Value then
script.Values.SpellValue.Value = 0
end
end
if (key == “q”) then
script.Values.SpellValue.Value = script.Values.SpellValue.Value-1
if script.Values.SpellValue.Value < 0 then
script.Values.SpellValue.Value = script.Values.MaxSpells.Value
end
end

----------------------SPELL NAMES--------------------------------

while true do
wait()
if script.Values.SpellValue.Value == 0 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“Baby blue”)
script.Values.SpellValue.SpellName.Value = “Protego”

wait()
if script.Values.SpellValue.Value == 0 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“Baby blue”)
script.Values.SpellValue.SpellName.Value = “Expecto Patronum”

elseif script.Values.SpellValue.Value == 1 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“New Yeller”)
script.Values.SpellValue.SpellName.Value = “Episkey”

elseif script.Values.SpellValue.Value == 2 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“White”)
script.Values.SpellValue.SpellName.Value = “Lumos”

elseif script.Values.SpellValue.Value == 3 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“White”)
script.Values.SpellValue.SpellName.Value = “Nox”

elseif script.Values.SpellValue.Value == 4 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“Really red”)
script.Values.SpellValue.SpellName.Value = “Expelliarmus”

elseif script.Values.SpellValue.Value == 5 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“Bright yellow”)
script.Values.SpellValue.SpellName.Value = “Rictusempra”

elseif script.Values.SpellValue.Value == 6 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“Medium red”)
script.Values.SpellValue.SpellName.Value = “Stupefy”

elseif script.Values.SpellValue.Value == 7 then
script.Parent.Lumos.Light.BrickColor = BrickColor.new(“Bright yellow”)
script.Values.SpellValue.SpellName.Value = “Levicorpus”
end
while WandEnabled == true do
wait()
game.Players.LocalPlayer.PlayerGui:FindFirstChild(“SpellGui”).Frame.Display.Text = script.Values.SpellValue.SpellName.Value
end
end
end
end

---------------------SPELL FUNCTIONS-----------------------------

function Protego()
if game.Players.LocalPlayer.Character:FindFirstChild(“Protego”) ~= nil then return end
local Prot = game.Lighting.SpellExtras.Protego:Clone()
Prot.Parent = game.Players.LocalPlayer.Character:FindFirstChild(“HumanoidRootPart”)
Prot.Position = game.Players.LocalPlayer.Character.Head.Position
Prot.Transparency = 0.5
Casting = true
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)

wait(7)

Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X-1,Prot.Size.Y-1,Prot.Size.Z-1)
wait()
Prot.Size = Vector3.new(Prot.Size.X+1,Prot.Size.Y+1,Prot.Size.Z+1)
wait()
Prot:remove()
wait(2)
Casting = false
end


function Episkey()
WandEquipped:Stop()
WandCasting:Play()
Casting = true

script.Parent.Handle.Cast:Play()

local Spell = Instance.new(“Part”)
Spell.formFactor = “Symmetric”
Spell.Shape = “Ball”
Spell.Size = Vector3.new(2,2,2)
Spell.TopSurface = “Smooth”
Spell.BottomSurface = “Smooth”
Spell.Transparency = 1
Spell.CanCollide = false
Spell.Parent = game.Workspace
Spell.Name = “Episkey”
Spell.CFrame = script.Parent.Handle.CFrame * CFrame.new(0,2,0)
-----SPELL SCRIPT-------
local SpellS = script.SpellScripts.Episkey:Clone()
SpellS.Parent = Spell
local Owner = script.Values.WandOwner:Clone()
Owner.Parent = SpellS

local SpellEFX = script.SpellEffects.Episkey:Clone()
SpellEFX.Parent = Spell
SpellEFX.Enabled = true

local BodVel = Instance.new(“BodyVelocity”)
BodVel.Parent = Spell
BodVel.velocity = ((game.Players.LocalPlayer.Character.Humanoid.TargetPoint - Spell.Position).unit) * 100
WandEquipped:Play()
wait(2)
Spell:remove()
Casting = false
end


function Lumos()
if LumosSP == true then return end
LumosSP = true
script.Parent.Handle.Lumos.Enabled = true
wait()
script.Parent.Lumos.Transparency = 0.9
wait()
script.Parent.Lumos.Transparency = 0.8
wait()
script.Parent.Lumos.Transparency = 0.7
wait()
script.Parent.Lumos.Transparency = 0.6
wait()
script.Parent.Lumos.Transparency = 0.5
end

function Nox()
if LumosSP == false then return end
LumosSP = false
script.Parent.Handle.Lumos.Enabled = false
wait()
script.Parent.Lumos.Transparency = 0.6
wait()
script.Parent.Lumos.Transparency = 0.7
wait()
script.Parent.Lumos.Transparency = 0.8
wait()
script.Parent.Lumos.Transparency = 0.9
wait()
script.Parent.Lumos.Transparency = 1
end


function Expelliarmus()
WandEquipped:Stop()
WandCasting:Play()
Casting = true

script.Parent.Handle.Cast:Play()

local Spell = Instance.new(“Part”)
Spell.formFactor = “Symmetric”
Spell.Shape = “Ball”
Spell.Size = Vector3.new(2,2,2)
Spell.TopSurface = “Smooth”
Spell.BottomSurface = “Smooth”
Spell.Transparency = 1
Spell.CanCollide = false
Spell.Parent = game.Workspace
Spell.Name = “Expelliarmus”
Spell.CFrame = script.Parent.Handle.CFrame * CFrame.new(0,2,0)
-----SPELL SCRIPT-------
local SpellS = script.SpellScripts.Expelliarmus:Clone()
SpellS.Parent = Spell
local Owner = script.Values.WandOwner:Clone()
Owner.Parent = SpellS

local SpellEFX = script.SpellEffects.Expelliarmus:Clone()
SpellEFX.Parent = Spell
SpellEFX.Enabled = true

local BodVel = Instance.new(“BodyVelocity”)
BodVel.Parent = Spell
BodVel.velocity = ((game.Players.LocalPlayer.Character.Humanoid.TargetPoint - Spell.Position).unit) * 100
WandEquipped:Play()
wait(2)
Spell:remove()
Casting = false
end


function Rictusempra()
WandEquipped:Stop()
WandCasting:Play()
Casting = true

script.Parent.Handle.Cast:Play()

local Spell = Instance.new(“Part”)
Spell.formFactor = “Symmetric”
Spell.Shape = “Ball”
Spell.Size = Vector3.new(2,2,2)
Spell.TopSurface = “Smooth”
Spell.BottomSurface = “Smooth”
Spell.Transparency = 1
Spell.CanCollide = false
Spell.Parent = game.Workspace
Spell.Name = “Rictusempra”
Spell.CFrame = script.Parent.Handle.CFrame * CFrame.new(0,2,0)
-----SPELL SCRIPT-------
local SpellS = script.SpellScripts.Rictusempra:Clone()
SpellS.Parent = Spell
local Owner = script.Values.WandOwner:Clone()
Owner.Parent = SpellS

local SpellEFX = script.SpellEffects.Rictusempra:Clone()
SpellEFX.Parent = Spell
SpellEFX.Enabled = true

local BodVel = Instance.new(“BodyVelocity”)
BodVel.Parent = Spell
BodVel.velocity = ((game.Players.LocalPlayer.Character.Humanoid.TargetPoint - Spell.Position).unit) * 100
WandEquipped:Play()
wait(2)
Spell:remove()
Casting = false
end


function Stupefy()
WandEquipped:Stop()
WandCasting:Play()
Casting = true

script.Parent.Handle.Cast:Play()

local Spell = Instance.new(“Part”)
Spell.formFactor = “Symmetric”
Spell.Shape = “Ball”
Spell.Size = Vector3.new(2,2,2)
Spell.TopSurface = “Smooth”
Spell.BottomSurface = “Smooth”
Spell.Transparency = 0
Spell.CanCollide = false
Spell.Parent = game.Workspace
Spell.Name = “Stupefy”
Spell.CFrame = script.Parent.Handle.CFrame * CFrame.new(0,2,0)
-----SPELL SCRIPT-------
local SpellS = script.SpellScripts.Stupefy:Clone()
SpellS.Parent = Spell
local Owner = script.Values.WandOwner:Clone()
Owner.Parent = SpellS
Spell.Stupefy.Disabled = false

local SpellEFX = script.SpellEffects.Stupefy:Clone()
SpellEFX.Parent = Spell
SpellEFX.Enabled = true

local BodVel = Instance.new(“BodyVelocity”)
BodVel.Parent = Spell
BodVel.velocity = ((game.Players.LocalPlayer.Character.Humanoid.TargetPoint - Spell.Position).unit) * 100
WandEquipped:Play()
wait(2)
Spell:Destroy()
Casting = false
end


function Levicorpus()
WandEquipped:Stop()
WandCasting:Play()
Casting = true

script.Parent.Handle.Cast:Play()

local Spell = Instance.new(“Part”)
Spell.formFactor = “Symmetric”
Spell.Shape = “Ball”
Spell.Size = Vector3.new(2,2,2)
Spell.TopSurface = “Smooth”
Spell.BottomSurface = “Smooth”
Spell.Transparency = 1
Spell.CanCollide = false
Spell.Parent = game.Workspace
Spell.Name = “Levicorpus”
Spell.CFrame = script.Parent.Handle.CFrame * CFrame.new(0,2,0)
-----SPELL SCRIPT-------
local SpellS = script.SpellScripts.Levicorpus:Clone()
SpellS.Parent = Spell
local Owner = script.Values.WandOwner:Clone()
Owner.Parent = SpellS

local SpellEFX = script.SpellEffects.Levicorpus:Clone()
SpellEFX.Parent = Spell
SpellEFX.Enabled = true

local BodVel = Instance.new(“BodyVelocity”)
BodVel.Parent = Spell
BodVel.velocity = ((game.Players.LocalPlayer.Character.Humanoid.TargetPoint - Spell.Position).unit) * 100
WandEquipped:Play()
wait(2)
Spell:remove()
Casting = false
end

Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)
mouse.KeyDown:connect(onKeyDown)

Damage script:

function onTouch(Impact) 

if Impact.Name == “Protego” then
script.Parent:Destroy()
return
end
local humanoid = Impact.Parent:FindFirstChild(“Humanoid”)
if humanoid and script:FindFirstChild(“WandOwner”) and humanoid.Parent.Name == script:FindFirstChild(“WandOwner”).Value then
print(“Returning.”)
script.Parent:Destroy()
return
end
if (humanoid ~= nil) then
print(“Hitting Humanoid”)
humanoid:TakeDamage(15)
script.Parent:Destroy()
else
print(“Didn’t find a humanoid”)
wait(.1)
script.Parent:Destroy()
end
end

script.Parent.Touched:Connect(onTouch)

The script’s parent is a folder. You want to do:

script.Parent.Parent.PathToPart.Touched:Connect(onTouch)

Replace PathToPart with the path to whatever part you want the touches event to fire for.

Please format your code so that is easy to read, you can do this by doing
Example:

print("Hello World")

```lua
code
```

This code look very not clean and long, I would recommended you to re-make it using OOP (Object Oriented Programming).