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

OnTouched function help?

Asked by
NotSoNorm 777 Moderation Voter
9 years ago

idk, It seems pretty basic, but it ain't workin I keep gettin the error: touched is not a valid member of workspace :Line 9

1function onTouched(part)
2 local h = part.Parent:findFirstChild("Humanoid")
3 if h~=nil then
4  script.Parent.Parent.Parent = h.Parent
5  script:remove()
6 end
7end
8 
9script.Parent.Touched:connect(onTouched)
0
I presume this script is inside the brick you are touching? iNicklas 215 — 9y
0
yeah, I don't think it really needs a debounce though NotSoNorm 777 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

I think its where you say script.Parent.Parent.Parent = h.Parent theres an extra parent that would make it game, game is locked. so thats all you did wrong

1function onTouched(part)
2 local h = part.Parent:findFirstChild("Humanoid")
3 if h~=nil then
4  script.Parent.Parent = h.Parent --parent of script, parent of the parent of script is workspace
5  script:remove()
6 end
7end
8 
9script.Parent.Touched:connect(onTouched)
Ad

Answer this question