Hello,
So some before created this script and I wanted to know if there was a quick fix to my issue. Right now, the script is set to move a certain about of studs. Is there anyway to making this script so that it move to another bricks position? I.E If part A is located at (0,3,0) have Part B move to there? Thanks, Anthony
local detector = game.Workspace.Part.ClickDetector; -- 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(1, 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(12, 0, 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.
Hi!
Yes, there is a way. In your original script, the "cframe" variable refers to CFrame coordinates, but to change it to the position of a part, just do [parthere].CFrame!
I labelled PartB as the part that you want the curtain to move to. The variable is then put as "cframe = PartB.CFrame" so the curtain will go to that part's position while playing the tween.
local detector = game.Workspace.Part.ClickDetector; local tween_service = game:GetService("TweenService") local curtain = workspace:WaitForChild("Curtain"); local old_pos = curtain.CFrame; local first = false; local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut); local y = 50; local cframe; local PartB = part --Identify the part you want the curtain to move to. function move_part() if first == false then first = true; cframe = PartB.CFrame --The cframe goal for the curtain. else first = false; cframe = old_pos; end local goal = {CFrame = cframe}; local tween = tween_service:Create(curtain, info, goal); tween:Play(); end detector.MouseClick:Connect(move_part);
Click "Accept Answer" if this was what you were looking for! Comment if you have any more concerns!