Hi
I made a dresser and I want the drawer to move open when proximity prompt clicking the dresser.
This is what I have so far.
dresser = script.Parent
drawer = script.Parent.Parent.Drawer
workspace.Dressers.Dresser.ProximityPrompt.Triggered:Connect(function(player)
print("open")
end)
1 Like
Inside of the triggered function, make a tween and then put (tweenname):Play()
1 Like
How do I do this? I’m completely new to tweens.
1 Like
local TweenService = game:GetService("TweenService")
local drawer = script.Parent
local Tweeninf = TweenInfo.new() --TweenInfo
local drawerCFrame = TweenService:Create(drawer,Tweeninf, {
CFrame = drawer.CFrame * CFrame.new(0, 0, 5) -- 5 is how far the drawer opens.
})
local ProximityPrompt = script.Parent.ProximityPrompt
ProximityPrompt.Triggered:Connect(function()
drawerCFrame:Play() -- Plays the tween
end)
A basic script, this moves a part a little bit on the Z Axis.
2 Likes
Works perfectly, thank you! How do I make it return back to 0 when clicking it again? I assume if statement?
1 Like
Correct
local TweenService = game:GetService("TweenService")
local drawer = script.Parent
local Tweeninf = TweenInfo.new() --TweenInfo
local opened = false -- if your drawer is closed by default
local drawerCFrame = TweenService:Create(drawer,Tweeninf, {
CFrame = drawer.CFrame * CFrame.new(0, 0, 5) -- 5 is how far the drawer opens.
})
local returnDrawerCFRAME = TweenService:Create(drawer,Tweeninf, {
CFrame = drawer.CFrame * CFrame.new(0, 0, 0)
})
local ProximityPrompt = script.Parent.ProximityPrompt
ProximityPrompt.Triggered:Connect(function()
if opened == false then
opened = true
drawerCFrame:Play() -- Plays the tween
else
opened = false
returnDrawerCFRAME:Play()
end
end)
The 2nd tween returns it to it’s original position.
2 Likes
Ahh it works perfectly now! Thank you so much!! ![:smiley: :smiley:](https://doy2mn9upadnk.cloudfront.net/images/emoji/twitter/smiley.png?v=12)
1 Like