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

How to make a cframe curtain move up and down?

Asked by 6 years ago

Hello,

So I was searching the Wiki and found the Part Sliding way to move a brick. What I would like to do if be able to move a brick. It would have a button and when I click the button the brick would move up, just like a stage curtain. I am pretty fair at scripting but Cframe is my main weakness. I can't seem to find any useful scripts to look at. If someone could please assist me I would truly appreciate that.

Thanks, Ant

0
accept KingLoneCat's answer, he said you copied it without accepting it. It's just unfair to the person who coded the answer but they get no reputation. bossay8 8 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Hey Antux,

From what I understand of the purpose of your script is, there's a button(where it be a Gui or a Part doesn't matter, for this example I'm going to use a Part button) and when somebody presses that button the part goes up a certain amount of studs and when somebody presses the part again, the part comes back down a certain amount of studs. This is just some very simple tweening between CFrames/Positions. I'm going to show you how to do this below using TweenService.

local detector = script.Parent; -- Variable for the ClickDetector
local tween_service = game:GetService("TweenService") -- Variable for the TweenService
local curtain = workspace:WaitForChild("Curtain"); -- Variable for the Curtain
local old_pos = curtain.CFrame; -- Variable for the Curtain's CFrame that we will be position the Curtain by.
local first = false; -- Variable to keep track of whether the part's supposed to go up or down.
local info = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut); -- The TweenInfo. The part will take 2 seconds to reach either up or down in a perfect situation. It's going to move linearly.
local y = 50; -- Variable for the amount of studs the part will go up.
local cframe; -- Variable for the CFrame that the part will need to reach.

function move_part() -- Declaration of the function that will later be connected with the detector's MouseClick() event.
    if first == false then -- Checks if it's the first click of the user.
        first = true; -- Sets the 'first' variable to true since it is the first click.
        cframe = old_pos * CFrame.new(0, y, 0) -- Sets the CFrame the part will need to reach. (In this case straight up relative to the Curtain's old position.
    else -- If it's not the first click then it will go here.
        first = false; -- Sets the 'first' variable back to false since it's the second click.
        cframe = old_pos; -- Sets the CFrame back to it's initial position so that it can go back to where it started from.
    end -- end for the if statement to check if it's the first click or second click.

    local goal = {CFrame = cframe}; -- Variable for the goal now that we know what CFrame the part will need to go to.

    local tween = tween_service:Create(curtain, info, goal); -- The whole tween of the Curtain, including the instance, info and goal the part is trying to reach.

    tween:Play(); -- Plays the Tween animation on the part
end -- end for the function.

detector.MouseClick:Connect(move_part); -- Connects the function to the MouseClick() event of the ClickDetector.

Updated the script 'cause the old one had issues.

Well, I hope I helped and have a great day/night.

~~ KingLoneCat

Ad

Answer this question