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

Why isn't this OnTouched script working? [closed]

Asked by
Tycy8 15
10 years ago

So I'm making a curtain type model that disappears when I click on the button and comes back within 5 seconds. I tried following a tutorial from the Wiki but it isn't working.

This is the hierarchy on Explorer:

  • Model
    • Door
      • BodyA
      • BodyB
      • BodyC
      • BodyD
      • BodyE
      • Button
        • Click Detector
        • Mesh
        • Script

This is the script:

Door = script.Parent.Parent.Door
function onTouched(hit)
Door.BodyA.Transparency= 1
Door.BodyB.Transparency= 1
Door.BodyC.Transparency= 1
Door.BodyD.Transparency= 1
Door.BodyE.Transparency= 1
Door.BodyA.CanCollide= false
Door.BodyB.CanCollide= false
Door.BodyC.CanCollide= false
Door.BodyD.CanCollide= false
Door.BodyE.CanCollide= false
wait(5)
Door.BodyA.Transparency= 0
Door.BodyB.Transparency= 0
Door.BodyC.Transparency= 0
Door.BodyD.Transparency= 0
Door.BodyE.Transparency= 0
Door.BodyA.CanCollide= false
Door.BodyB.CanCollide= false
Door.BodyC.CanCollide= false
Door.BodyD.CanCollide= false
Door.BodyE.CanCollide= false
end
script.Parent.Touched:connect(onTouched)

Locked by adark, SanityMan, and TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

The script you posted is if you physically touch it. You need to change your connection line. I also added a debounce so the function doesn't keep spamming if people click it multiple times.

Door = script.Parent.Parent.Door
on = false

script.Parent.ClickDetector.MouseClick:connect(function()
    if on == false then
        on = true
        Door.BodyA.Transparency= 1
        Door.BodyB.Transparency= 1
        Door.BodyC.Transparency= 1
        Door.BodyD.Transparency= 1
        Door.BodyE.Transparency= 1
        Door.BodyA.CanCollide= false
        Door.BodyB.CanCollide= false
        Door.BodyC.CanCollide= false
        Door.BodyD.CanCollide= false
        Door.BodyE.CanCollide= false
        wait(5)
        Door.BodyA.Transparency= 0
        Door.BodyB.Transparency= 0
        Door.BodyC.Transparency= 0
        Door.BodyD.Transparency= 0
        Door.BodyE.Transparency= 0
        Door.BodyA.CanCollide= false
        Door.BodyB.CanCollide= false
        Door.BodyC.CanCollide= false
        Door.BodyD.CanCollide= false
        Door.BodyE.CanCollide= false
        on = false
    end
end)

1
Ok great thanks! Tycy8 15 — 10y
1
Thank me by accepting this answer! Shawnyg 4330 — 10y
Ad