Im not sure what went wrong. Im trying to move the button along with the sliding door with CFrame. The button has a click detector in it.
Here's the script:
--Waiting for objects to load local Configuration = script.Parent:WaitForChild("Configuration") local Code = Configuration:WaitForChild("Code") local TimeOpen = Configuration:WaitForChild("TimeOpen") local SlidingTime = Configuration:WaitForChild("SlidingTime") local Height = Configuration:WaitForChild("Height") local Button = script.Parent.Door:WaitForChild("Button"):WaitForChild("ClickDetector") local Door = script.Parent:WaitForChild("Door") --Tweening local tweenService = game:GetService("TweenService") local tweenInfo = TweenInfo.new(SlidingTime.Value,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0) --Other variables local open = false
--Fuction that plays when we click the button. Button.MouseClick:Connect(function(player) local newcode = game.ReplicatedStorage:WaitForChild("CodeDoor"):InvokeClient(player) --we invoke the players client and wait until they return the code
if newcode == Code.Value and open == false then
print('correct')
open = true
local goal1 = {CFrame = Door.CFrame + Vector3.new(-3,Height.Value,0)} --CFrame of the door when it moves up, used for tween1
local goal2 = {CFrame = Door.CFrame} --Devault CFrame for the door, used for tween2
local goal3 = {CFrame = Button.CFrame + Vector3.new(-3,Height.Value,0)}
local goal4 = {CFrame = Button.CFrame}
local tween1 = tweenService:Create(Door,tweenInfo,goal1) --opening tween
local tween2 = tweenService:Create(Door,tweenInfo,goal2) --closing tween
local tween3 = tweenService:Create(Button,tweenInfo,goal3)
local tween4 = tweenService:Create(Button,tweenInfo,goal4)
--Light (part) color changes
--PointLight color changes (optional, disabled by default)
tween1:Play() --The door opens because we play the opening tween
wait(TimeOpen.Value)
tween2:Play() --The door closes because we tween the doors CFrame back to normal
wait(SlidingTime.Value)
--Light (part) color changes
--PointLight color changes (optional, disabled by default)
open = false
else --If the code is not correct, we just print "incorrect"
print('incorrect')
end
end)

1 comment
Hey!! Click accept answer on the side of my answer to view your question as answered. It will help me a lot too.