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

OnTouched function help?

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)

2 comments

0

I presume this script is inside the brick you are touching?

0

yeah, I don't think it really needs a debounce though

1 answer

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)

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