Hi, I am trying to make a tweening effect where the player presses a button, and it plays that animation, but for some reason the camera goes back to its original position after the tweening animation ends. I am not sure whether it is another code doing it or If I messed something up on the tweening code. The screenshots and codes I provided, what I think, are involved in the situation (I also included a video to make it more understandable to what I am trying to achieve):
ServerScriptService:
local remote = game.ReplicatedStorage.Menu
game.Players.PlayerAdded:Connect(function(plr)
remote:FireClient(plr)
end)
Lines 16 through 28 from the Main Script of the ScreenGui:
function mainMenu()
repeat
cam.CameraType = Enum.CameraType.Scriptable
wait(.1)
until cam.CameraType == Enum.CameraType.Scriptable
textlabel.Visible = true
playbutton.Visible = true
cam.CFrame = camPart.CFrame
end
remote.OnClientEvent:Connect(function()
mainMenu()
end)
The local script parented to the button that plays the tween:
I notice you got a pretty cool camera movement that looks like it follows the mouse. Is it possible that the code is setting it back to the camPart's CFrame? If it is, you should have the camera shake effect be relative to the workspace.CurrentCamera CFrame and not another part.
Try taking the amount that the mouse changes the angle and reverse it (not visually), and then on the next frame put it to the original with the mouse movement changing the angle relative to the reversed CFrame so that you don’t need to make it relative to the camera part CFrame. If you don’t understand this let me know. I can rewrite your script soon if you would like.
I’ll try it out when I get out of classes. Few questions though, do I replace the old script with this one? If so, will this solve the problem with the tweening?
-- Variables
local cam = workspace.CurrentCamera
local camPart = workspace.CamPart
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
-- Set Camera
repeat
wait()
cam.CameraType = Enum.CameraType.Scriptable
until
cam.CameraType == Enum.CameraType.Scriptable
-- Move cam
local maxTilt = 10
game:GetService("RunService").RenderStepped:Connect(function()
cam.CFrame = camPart.CFrame * CFrame.Angles(
math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
0
)
end)
with the code I provided. The code shown here is YOUR code. You replace this with mine that I showed in my previous post. Also, to answer the latter question, the code I showed you earlier should solve the problem with the tweening. I tested out camera tweening in my test place with this and it worked fine.