[Touched is not a valid member of Folder] problem (need help)

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.

> function onTouch(Impact)
> 
> if Impact.Name == "Protego" then script.Parent:remove() return end
> 
> local humanoid = Impact.Parent:FindFirstChild("Humanoid")
> 
> if humanoid.Parent.Name == script:FindFirstChild("WandOwner").Value then script.Parent:remove() return end
> 
> if (humanoid ~= nil) then
> 
> humanoid.Health = humanoid.Health - 25
> 
> script.Parent:remove()
> 
> else
> 
> wait(.1)
> 
> script.Parent:remove()
> 
> end
> 
> end
> 
> script.Parent.Touched:connect(onTouch)

Probably because “script.parent” is a Folder… Touched function only works on base parts I think, Make sure the parent of your script is the actual part you want to be touched

The script is in a folder therefore in the last line:

script.Parent.Touched:Connect(onTouch)

you are indexing the folder with Touched key.
Touched as an event is only present in all instances of class derived from BasePart. That is why you are getting an error. One of the solutions is to put the script in a part that you want the Touched event to work for, or change the last line so that you are referencing a part not a folder.

I got another script that creates a ball and put the script inside.

So it isn’t a folder ???
textlmit

The error says something different. The script is either in a folder or you did not give us the script the error was raised for.

The ball that holds the script.

Baseplate - Roblox Studio 12-05-2020 18_47_47 (3)

Any suggestions ???

Are you checking what happens to the part and script while it’s in explorer? You can try adding lines like print(script.Parent,script.Parent.Parent,script.WandOwner) to find out where the script is going.

I know where the script is going but the dammage/dmg effect is nil!

So does that mean the line that has script.Parent.Touched:connect(onTouch) is not the error, and humanoid.Health = humanoid.Health - 25 is the error?

The error is:

19:01:46.993 - Touched is not a valid member of Folder

19:01:46.994 - Stack Begin

19:01:46.994 - Script ‘Players.TheDeadTed14.Backpack.Wand.WandFunction.SpellScripts.Stupefy’, Line 6

19:01:46.994 - Stack End

Players.TheDeadTed14.Backpack.Wand.WandFunction.SpellScripts.Stupefy errored!

Reason: Touched is not a valid member of Folder

Trace: Players.TheDeadTed14.Backpack.Wand.WandFunction.SpellScripts.Stupefy, line 6

  • print(script.Parent) before the function, tell me what it prints

  • what is “Protego”?

Protego (Harry Potter) stops the spell.

Nothing printed???
textlimit

In that case it could be that your script is running before script.Parent is defined. You could try using something like repeat wait() until script.Parent ~= nil before running the rest of your code.

Yes u should wait for the part to load in.

local part = game.Workspace:WaitForChild("Stupefy", 2)

I will try :smiley:
textlimit textlimit

Oh, seriously:

19:24:15.011 - Infinite yield possible on ‘Workspace:WaitForChild(“Stupefy”)’

19:24:15.012 - Stack Begin

19:24:15.012 - Script ‘Players.TheDeadTed14.Backpack.Wand.WandFunction.SpellScripts.Stupefy’, Line 1

19:24:15.012 - Stack End