• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


30 Nov, 2024

Updated at 05 Dec, 2024

Returning to player camera not working

Hi, I am currently making a script using a camera for my main menu, but weirdly, it doesn’t work like it’s supposed to. I tried using the Studio’s AI Assistant thing but no matter how many times I’ve asked, it still doesn’t want to run. I’ve also searched everything in the DevForum, but still, none of them seem to work.

It consists of two scripts,
Here’s the main script (“Cam”, works just fine):

--overall sets the camera to its position; CamPart.

local camPart = workspace:WaitForChild("CamPart")
local camera = workspace:WaitForChild("Camera")
local gui = game.StarterGui:WaitForChild("MainMenu")

function tween(obj, dur, cmd)
    return game:GetService('TweenService'):Create(obj, dur, cmd)
end

workspace.Camera.CameraType = Enum.CameraType.Scriptable
local cameraTween = tween(camera, TweenInfo.new(3), {CFrame = camPart.CFrame})

cameraTween:Play()
cameraTween.Completed:Connect(function()
    game:GetService("RunService").RenderStepped:Connect(function()
        camera.CFrame = camPart.CFrame
    end)
end)

and here’s the 2nd script (“LocalScript”), which I am having trouble with:

local gui = game.StarterGui.MainMenu
local camPart = workspace:WaitForChild("CamPart")
local button =  script.Parent
local camera = workspace.Camera

-- return the camera to player
button.MouseButton1Click:Connect(function()
	--making sure it works
	print("returnplayer executed")
	
	gui.Enabled = false
	--returning camera to player
	camera.CameraType = Enum.CameraType.Custom
	camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	print("success")
end)

Now, weirdly, the print function works just fine, but hiding the GUI and returning the camera to the player doesn’t work.

Here’s the hierarchy of the properties


+CamPart located in Workspace

Here’s what it looks like:



FYI, there are no errors in the output. It just doesn’t want to return the camera and hide the GUI.

Waiting for your help!

12 posts - 2 participants

Read full topic