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

I need help with a door script using CFrame?

Asked by 5 years ago

A door takes too long to open. Im using CFrame here is the script:

function onClicked()
if script.Parent.Value.Value == true then
script.Parent.Value.Value = false
if script.Parent.V.Value == true then
script.Parent.V.Value = false
wait(0)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.35) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
wait(0.01)

elseif script.Parent.V.Value == false then
script.Parent.V.Value = true

script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.05, 0, -0.36) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.285) * CFrame.fromEulerAnglesXYZ(0, 0, 0)
wait(0.01)

end

script.Parent.Value.Value = true
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
connect is deprecated so use Connect. and PLEASE indent your code I can't reas that. User#19524 175 — 5y
0
use a for loop :v VewixxPlayer 67 — 5y
0
Tween the door instead of cframes xXiNotoriousXx 31 — 5y
0
Have you heard of a for loop, and really you should be using tweens for that (says the person who does not use tweens for doors). AlphaGamer150 101 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

I would use tweening for the doors, you can get a tutorial from alvin bloxs here.

FYI does not have to be sliding, just adjust it. https://www.youtube.com/watch?v=ya4GzyZdLMA

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

To do this, tweening should be used.

An example is as follows:

local TweenService = game:GetService("TweenService") -- Get the tween service, we need this to make a tween

local Goal = {} -- Make a blank dictionary this will be used to indicate where we want the part to be.
Goal.CFrame = CFrame.new(X, Y, Z) -- Say where we want the part to end up

local Tween = TweenService:Create(Door, TweenInfo.new(), Goal) -- Create a new tween using the Object we want to move (in this case the door), some tween info (we will use defualt with TweenInfo.new()) and the Goal we want the part to reach

Tween:Play() -- Play the tween the part will be moved to the goal over the course of 1 second.

Please refer to the Roblox Developer Hub for more information: https://www.robloxdev.com/api-reference/class/TweenService

Answer this question