OnTouch part opens a secret part

Basically I am trying to make something which has a part, so when the player touches that part the door will slide open.

Similar to the Roblox Deathrun secret room, when you activated it to open the door.

Help me if possible.

What have you attempted so far?

2 Likes

Well I am confused with how I will do this, I am trying to seek help to let me understand what I should do.

This is a api wiki thing that can help:

https://developer.roblox.com/api-reference/event/BasePart/Touched

1 Like

Try creating a function to hook to the Touched event.

1 Like

How will I make it so when OnTouch is activated the door will slide across slightly.

You could use CFraming or TweenService! Tweening is more smooth, whereas CFraming uses for loops.

1 Like

Alright, this looks simple enough! If you want a smooth animation of a part moving a direction then you should use the Tween service.

local part = script.Parent
 
local tweeningInformation = TweenInfo.new(
   
5, -- Length
Enum.EasingStyle.Bounce, -- Easing style of the TweenInfo
Enum.EasingDirection.Out, -- Easing direction of the TweenInfo
10, -- Number of times the tween will repeat   
true, -- Should the tween repeat?
2 -- Delay between each tween  
)
 
local partProperties = {
    Size = Vector3.new(20,20,20);
    Color = Color3.new(255, 0, 0);
    Transparency = 0.5
}
 
local Tween = tweenService:Create(part,tweeningInformation,partProperties)
Tween:Play()

You could make a module function for this if you going to make a lot of door move to other direction!
Now all you have to do it make it do the door does this when a player touches it. The Touched event should have a debounce so it won’t spam the door as well as a animation for it going back. If you need me to show a example of this you can just replay!

5 Likes

Yea, in this case, he should use the TweenService, it’s more efficient than using a cframe loop.

1 Like

I think he already know about the touched event, he asking how to make a part move in a direction when touched

1 Like