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

onTouched is not a valid member of Workspace?

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)

4 comments

0

try change waves.onTpuched(hit) to waves:onTpuched(hit)

0

I have no idea why it is not working.

0

@dar I'll try.

0

onTouched is not a valid member of WedgePart

3 answers

✓ Accepted answer

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)

3 comments

0

Doesn't work e.e

0

It seems like that should work but it's not e.e

0

try using woolhat's.

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