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

function onTouched(part)
 local h = part.Parent:findFirstChild("Humanoid")
 if h~=nil then 
  script.Parent.Parent.Parent = h.Parent
  script:remove()
 end
end

script.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

function onTouched(part)
 local h = part.Parent:findFirstChild("Humanoid")
 if h~=nil then 
  script.Parent.Parent = h.Parent --parent of script, parent of the parent of script is workspace
  script:remove()
 end
end

script.Parent.Touched:connect(onTouched)

Ad

Answer this question