Hello friends! I’m currently working on a camera moving system for my fnaf 4 inspired game!
I think I have tackled most major problems, but have I done them efficiently through my code is the question
Essentially, when you click on a button, it should disable the other buttons and tween the camera to the part. It will then give it some time, give a prompt to go back to the original position and then you can repeat.
You can test this code at the start of my game if you feel so!
https://www.roblox.com/games/8491443345/WIP#!/game-instances
function LoadRoom()
RoomAmbience:Play()
RoomAmbience.Looped = true
wait(cutsceneTime)
camera.CFrame = Maincamera.CFrame
-- Load camera Ui's
local Screen = Instance.new("ScreenGui")
Screen.Parent = PlayerGui
local ButtonLeft = Instance.new("TextButton")
ButtonLeft.Parent = Screen
ButtonLeft.Size = UDim2.new(0.040,0,0.120,0)
ButtonLeft.AnchorPoint = Vector2.new(0, 0.5)
ButtonLeft.Position = UDim2.new(0, 0, 0.5, 0)
ButtonLeft.Visible = true
local ButtonRight = Instance.new("TextButton")
ButtonRight.Parent = Screen
ButtonRight.Size = UDim2.new(0.040,0,0.120,0)
ButtonRight.AnchorPoint = Vector2.new(1, 0.5)
ButtonRight.Position = UDim2.new(1, 0, 0.5, 0)
ButtonRight.Visible = true
local ButtonBack = Instance.new("TextButton")
ButtonBack.Parent = Screen
ButtonBack.Size = UDim2.new(0.040,0,0.120,0)
ButtonBack.AnchorPoint = Vector2.new(0.5, 1)
ButtonBack.Position = UDim2.new(0.5, 0, 1, 0)
ButtonBack.Visible = true
-- Events
ButtonLeft.MouseButton1Click:Connect(function()
ButtonLeft.Visible = false
ButtonRight.Visible = false
ButtonBack.Visible = false
local tweenInfo = TweenInfo.new(
3,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local TweenToLeftDoor = TweenService:Create(camera, tweenInfo, {CFrame = LeftCamera.CFrame})
TweenToLeftDoor:Play()
PositionLeftDoor:FireServer()
task.wait(3)
ButtonBack.Visible = true
end)
ButtonRight.MouseButton1Click:Connect(function()
ButtonRight.Visible = false
ButtonLeft.Visible = false
ButtonBack.Visible = false
local tweenInfo = TweenInfo.new(
3,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local TweenToRightDoor = TweenService:Create(camera, tweenInfo, {CFrame = RightCamera.CFrame})
TweenToRightDoor:Play()
PositionRightDoor:FireServer()
task.wait(3)
ButtonBack.Visible = true
end)
ButtonBack.MouseButton1Click:Connect(function()
if ButtonLeft.Visible == false or ButtonRight.Visible == false then
ButtonLeft.Visible = false
ButtonRight.Visible = false
ButtonBack.Visible = false
end
local tweenInfo = TweenInfo.new(
3,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local TweenBack = TweenService:Create(camera, tweenInfo, {CFrame = Maincamera.CFrame})
TweenBack:Play()
task.wait(3)
ButtonLeft.Visible = true
ButtonRight.Visible = true
end)
end