This script is inside the part. The script is :
local waves = game.workspace.Tsunami["TsunamiParts"] function onTouched(hit) if waves.onTouched(hit)then script.parent.Anchored = false end end script.Parent.Touched:connect(onTouched)
The first problem is on line five where you consider onTouched
to be a property of waves when there is no such property. In addition if you want to get all the children (parts) of a model, you use the GetChildren()
method. In order to anchor the part when any part in waves is touched, you would do something like this:
local waves = game.Workspace.Tsunami function onTouched (hit) if hit:IsDescendantOf(waves) then script.Parent.Anchored = false end end script.Parent.Touched:Connect(onTouched)
In the onTouched
function, the script is first checking whether or not the part that touched the part is part of the waves. If it is, the part's Anchored
property is set to false
.
**What's the error: ** On line 5, you're calling a function "onTouched", as though it's a function of the TsunamiParts Model.
**What's the solution: ** I'd imagine that you're trying to see if the touching part (hit) exists, and if so, anchor the parent of the script. You can check if hit exists easily, by doing:
local waves = game.workspace.Tsunami["TsunamiParts"] function onTouched(hit) if hit and hit:IsDescendantOf(waves) then script.parent.Anchored = false end end script.Parent.Touched:connect(onTouched)
Line 5, you're basically saying "onTouched" is a children of waves.
local waves = game.Workspace.Tsunami["TsunamiParts"] waves.Touched:connect(function(hit) script.Parent.Anchored = false end)