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

onTouched is not a valid member of Workspace?

Asked by 7 years ago

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)
0
try change waves.onTpuched(hit) to waves:onTpuched(hit) darkzerobits 92 — 7y
0
I have no idea why it is not working. devconstruct 4 — 7y
0
@dar I'll try. devconstruct 4 — 7y
0
onTouched is not a valid member of WedgePart devconstruct 4 — 7y

3 answers

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
7 years ago
Edited 7 years ago

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.

Ad
Log in to vote
0
Answered by
WoolHat 53
7 years ago
Edited 7 years ago

**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)

Log in to vote
0
Answered by
Astralyst 389 Moderation Voter
7 years ago

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)
0
Doesn't work e.e devconstruct 4 — 7y
0
It seems like that should work but it's not e.e devconstruct 4 — 7y
0
try using woolhat's. Astralyst 389 — 7y

Answer this question