Hi. I’m having issue with figuring out the below.
At the moment when activated the DoorRoot moves to 90 degrees.
I’m trying to make it increase by 90 degrees, not move to 90 degrees.
local Door = script.Parent.Parent
local DoorRoot = Door.PrimaryPart
local PositionPart = Door.Position
local Distance = 4.6
local DoorSwingInfo = TweenInfo.new()
local Value = false
local DoorOpen = TweenService:Create(DoorRoot, DoorSwingInfo, {
CFrame = Door.CFrame * CFrame.Angles(0, math.rad(90), 0)
})
local DoorClose = TweenService:Create(DoorRoot, DoorSwingInfo, {
CFrame = Door.CFrame * CFrame.Angles(0, math.rad(0), 0)
})
RemoteEvent.OnServerEvent:Connect(function(Player)
local Character = Player.Character
if (Character.HumanoidRootPart.Position - PositionPart.Position).Magnitude <= Distance then
if Value == false then
Value = true
DoorOpen:Play()
else
Value = false
DoorClose:Play()
end
end
end)
Edited code
local Door = script.Parent.Parent
local DoorRoot = Door.PrimaryPart
local PositionPart = Door.Position
local Distance = 4.6
local DoorSwingInfo = TweenInfo.new(.5)
local Value = false
local RootCF = DoorRoot.CFrame
function TweenDoor(Direction)
TweenService:Create(DoorRoot, DoorSwingInfo, {CFrame = RootCF * CFrame.Angles(0, math.rad(90) * Direction, 0)}):Play()
end
RemoteEvent.OnServerEvent:Connect(function(Player)
local Character = Player.Character
if (Character.HumanoidRootPart.Position - PositionPart.Position).Magnitude <= Distance then
if Value == false then
Value = true
TweenDoor(1)
else
Value = false
TweenDoor(0)
end
end
end)
Summary: Simply made a function for him which would work with different directions and more control instead of having multiple tweens for both closing the door and opening it.
local RootCF = DoorRoot.CFrame
function TweenDoor(Direction)
TweenService:Create(DoorRoot, DoorSwingInfo, {CFrame = RootCF * CFrame.Angles(0, math.rad(90) * Direction, 0)}):Play()
end
Direction being set to 1 would open the door, 0 close the door, 0.5 open the door half-way etc.