Hi. I’m having trouble with my script, I’m not sure why as there’s no errors, but it’s just not working.
Basically, I have the camera set to a part when the player joins. There’s a play button, and when the button is clicked I’m trying to get it so that the camera resets back to the player. The camera also follows the cursor in the play screen. I’m not sure how to disable this but I can’t even get to the point of resetting it properly.
Here’s how it looks in-game.
This is the script that sets the camera, and makes it follow the cursor smoothly.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local run = game:GetService("RunService")
local cp = workspace:WaitForChild("Cam")
local cam = workspace.CurrentCamera
local maxDegree = math.rad(30)
repeat
cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable
run.RenderStepped:Connect(function()
local np = Vector2.new(mouse.X, mouse.Y)
local centre = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
local difference = np - centre
local outcome = Vector2.new((difference.Y/centre.Y)*maxDegree, (difference.X/centre.X)*maxDegree)
cam.CFrame = CFrame.Angles(-outcome.X, -outcome.Y,0) + cp.Position
end)
I’m very nooby, and I put this little system together using my limited knowledge & some tutorials. Everything else works except for the camera resetting.
I did that here, after the button is pressed it tweens out, enables all the game’s gui and at the bottom it sets it back to Enum.CameraType.Custom. It doesn’t work.
I see. I was going to attempt that later on, I didn’t know that was the issue here. How would I even go about doing that? My first thought is to destroy the script after you click the button.
I replaced my code with the example you gave, and put the Unbind after clicking the button. Is this how you meant for it to be used? Now, the camera is never set to where it’s supposed to be, and it gets stuck looking in one direction.
Try deleting the part where you set the camera’s cframe to the player’s head after you press the button, if that doesn’t work then try playing with the bind priority (the 0 in bind to render step)
That doesn’t fix it either, the camera still doesn’t get set to the Cam part inside the store, and pressing the play button doesn’t do anything either.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local run = game:GetService("RunService")
local cp = workspace:WaitForChild("Cam")
local cam = workspace.CurrentCamera
local maxDegree = math.rad(30)
repeat
cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable
run:BindToRenderStep("MenuCamera", 0, function()
local np = Vector2.new(mouse.X, mouse.Y)
local centre = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
local difference = np - centre
local outcome = Vector2.new((difference.Y/centre.Y)*maxDegree, (difference.X/centre.X)*maxDegree)
cam.CFrame = CFrame.Angles(-outcome.X, -outcome.Y,0) + cp.Position
end)
game.StarterGui.WelcomeIntroGui.Welcome.Play.MouseButton1Click:Connect(function()
run:UnbindFromRenderStep("MenuCamera")
end)
I got rid of the need to go between two scripts, they are now completely separate. Everything regarding the camera is in this script.