Sup, I’m making a main menu for me and my friend’s horror game. I’m trying to create a play button that switches from the main menu camera to the player’s character.
The camera is made to slightly follow the cursor while in the main menu. And the problem is I don’t know how to get it back to normal.
I’ve already made a function for the camera to switch back to player’s character but the part where the cursor follows the camera messes everything up.
This how it looks like when I tried to switch back to player’s character:
I had modified it and added a few function so it could work with other scripts.
This is the updated script:
--// Variables
local Sounds = game.Workspace.MainMenu.SFX
local player = game.Players.LocalPlayer
local pb = game.Workspace.MainMenu.Main.MainMenu.MainFrame.Buttons.Play
local cam = workspace.CurrentCamera
local camPart = workspace["CameraPart"]
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
--// Set cam
repeat
wait()
cam.CameraType = Enum.CameraType.Scriptable
until
cam.CameraType == Enum.CameraType.Scriptable
--// Move cam
local function showMainMenu()
local maxTilt = 5
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)
--PlayFunction--
pb.MouseButton1Click:Connect(function()
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = player.Character
Sounds.Click:Play()
end)
end
local showMainMenuEvent = game.ReplicatedStorage:WaitForChild("ShowMainMenu")
showMainMenuEvent.Event:Connect(showMainMenu)
showMainMenu() -- Call the function to display the main menu when the game starts
But with the function showMainMenu I couldn’t move the ‘‘Move cam’’ part of the script in other parts of the script to modify it. And removing the showMainMenu function the Move cam doesn’t work anymore.
I couldn’t quite find a way to fix the problem so I had to make this post in hopes someone would help.
Would be much appriciated.
Well You Can Get The Character By Doing This: local Character = player.Character or player.CharacterAdded:Wait() And Then Remove player So It Should Look Like This: cam.CameraSubject = Character.Humanoid
I don’t think that making shortcuts will quite help with the problem. I need to figure out how to remove the camera following the cursor when the playbutton is clicked. Still glad you put your effort into trying to help.
I Would Assume To Do At a the Playbutton Put This: cam.CFrame = camPart.CFrame * CFrame.Angles() (I kinda suck if it doesn’t work I don’t know what to do)
I understand, I recommend reading and making a few devforum topics until you get the hang of scripting, and then help others. But it’s still very nice of you to try help others even if you have more limited knowledge of scripting.
I mean It could work, but it would make the main menu camera single-use and it would probably happen for the whole server, and I forgot to mention that the GUI is a SurfaceUI meaning it works like an image on a part.
It is a local script, but if I were to destroy a part using a locally sided script it would either make the destruction server sided or simply print out an error message, nevertheless I’ll still try that now.
It had the same effect. I changed the numbers but it either locked the camera in one place while focusing on the player or focused on the menu without movement.
I may be wrong here, but to start off, you’re changing the CameraType back to Custom but you’re altering it still. Perhaps change the type of the camera later on in the script. Secondly, models, which is what the character is, cannot be used as CameraSubjects to my knowledge. Instead, try doing something like this:
camera.CameraSubject = player.Character:FindFirstChild(["whatever your humanoid's name is'"]) --Put in your humanoid there!
camera.CameraType = Enum.CameraType.Custom
Changing it to the character’s humanoid will re-enable that default Roblox camera movement. Hopefully this helps!
I updated the code but there was still the same effect as in the video. Maybe I should find an alternative for making the camera slightly follow the cursor?
ah, i think i may see the problem now (?) cam.CameraSubject = player.Character:FindFirstChild({character, humanoid})
Replace the {character, humanoid} with just “Humanoid”
I believe i put that originally in my take of the script as a way of saying, “Put the humanoid here.” Sorry about that, and if this doesn’t solve it I don’t think I know the answer.