Bloxrrey
(aubrey)
March 14, 2021, 4:10am
#1
I am trying to make an intro screen for my game that has a camera that moves around with the mouse movement.
Everything works, but the camera isn’t resetting even though I set it to Custom. There are no errors in the output.
I tried game.RunService.RenderStepped:Disconnect() because I found that somewhere but it seems to not work. Here is the script.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character:WaitForChild("HumanoidRootPart").Anchored = true
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.IntroScreen.Camera.CFrame
local tweenService = game:GetService("TweenService")
local mainMenuGui = script.Parent.MainMenuGUI
local mainMenuBG = mainMenuGui:WaitForChild("Frame")
local playBtn = mainMenuBG:WaitForChild("Play")
local originalCFrame = camera.CFrame
local scaleFactor = 1000
game:GetService("RunService").RenderStepped:Connect(function()
local centreOfScreen = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2)
local mouseDistanceFromCentre = Vector3.new((-mouse.X - centreOfScreen.X) / scaleFactor, (mouse.Y - centreOfScreen.Y) / scaleFactor, 0)
camera.CFrame = originalCFrame * CFrame.new(originalCFrame.LookVector + mouseDistanceFromCentre)
end)
local playButtonClicked = false
playBtn.MouseButton1Click:Connect(function()
if playButtonClicked then return end
playButtonClicked = true
mainMenuBG:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 3, true)
wait(3)
character.HumanoidRootPart.Anchored = false
character.HumanoidRootPart.CFrame = workspace.IntroScreen.PlayerPos.CFrame
mainMenuGui:Destroy()
camera.CameraType = Enum.CameraType.Custom
end)
After the play button is clicked, the camera is stuck here.
Thanks!
1 Like
Try doing LoadCharacter()
as well? There’s been some weird issues with the Camera acting strange
2 Likes
Bloxrrey
(aubrey)
March 14, 2021, 4:30am
#3
No I haven’t, but I checked an the character loading and spawning works fine.
Unless there is some other reason you need to do LoadCharacter()
1 Like
Bloxrrey
(aubrey)
March 14, 2021, 4:36am
#4
Doesn’t seem to work any other suggestions?
1 Like
Just for debugging purposes, try putting the CameraType
through a repeat wait()
loop?
2 Likes
Bloxrrey
(aubrey)
March 14, 2021, 4:46am
#6
Once I do that, the script makes it a custom camera.
1 Like
repeat wait()
camera.CameraType = Enum.CameraType.Custom
until camera.CameraType == Enum.CameraType.Custom
You tried doing this right?
2 Likes
Bloxrrey
(aubrey)
March 14, 2021, 5:46am
#9
Yes i did and it worked but it cause it to only be custom camera
1 Like
RVCDev
(commitcookies)
March 14, 2021, 5:50am
#10
game:GetService("RunService").RenderStepped:Connect(function()
local centreOfScreen = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2)
local mouseDistanceFromCentre = Vector3.new((-mouse.X - centreOfScreen.X) / scaleFactor, (mouse.Y - centreOfScreen.Y) / scaleFactor, 0)
camera.CFrame = originalCFrame * CFrame.new(originalCFrame.LookVector + mouseDistanceFromCentre)
end)
I guess this is your problem, you aren’t unbinding or disconnecting it after pressing the play button?
You need to make a connection variable like:
local updateConnection = nil
updateConnection = RunService.RenderStepped:Connect()
thingtopress.MouseButton1Click:Connect(function()
if updateConnection then
updateConnection:Disconnect()
end
end)
2 Likes
Bloxrrey
(aubrey)
March 14, 2021, 5:58am
#12
Doesn’t seem to work here is my current code
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character:WaitForChild("HumanoidRootPart").Anchored = true
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.IntroScreen.Camera.CFrame
local tweenService = game:GetService("TweenService")
local mainMenuGui = script.Parent.MainMenuGUI
local mainMenuBG = mainMenuGui:WaitForChild("Frame")
local playBtn = mainMenuBG:WaitForChild("Play")
local originalCFrame = camera.CFrame
local scaleFactor = 1000
game:GetService("RunService").RenderStepped:Connect(function()
local centreOfScreen = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2)
local mouseDistanceFromCentre = Vector3.new((-mouse.X - centreOfScreen.X) / scaleFactor, (mouse.Y - centreOfScreen.Y) / scaleFactor, 0)
camera.CFrame = originalCFrame * CFrame.new(originalCFrame.LookVector + mouseDistanceFromCentre)
end)
local playButtonClicked = false
local updateConnection = nil
updateConnection = game:GetService("RunService").RenderStepped:Connect()
playBtn.MouseButton1Click:Connect(function()
if playButtonClicked then return end
playButtonClicked = true
mainMenuBG:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 3, true)
wait(3)
if updateConnection then
updateConnection:Disconnect()
end
character.HumanoidRootPart.Anchored = false
character.HumanoidRootPart.CFrame = workspace.IntroScreen.PlayerPos.CFrame
mainMenuGui:Destroy()
camera.CameraType = Enum.CameraType.Custom
end)
1 Like
RVCDev
(commitcookies)
March 14, 2021, 6:05am
#13
you need to define the variable updateConnection
then add updateConnection
at the game:GetService("RunService").RenderStepped:Connect(function()
:
updateConnection = game:GetService("RunService").RenderStepped:Connect(function()
local centreOfScreen = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2)
local mouseDistanceFromCentre = Vector3.new((-mouse.X - centreOfScreen.X) / scaleFactor, (mouse.Y - centreOfScreen.Y) / scaleFactor, 0)
camera.CFrame = originalCFrame * CFrame.new(originalCFrame.LookVector + mouseDistanceFromCentre)
end)
remove updateConnection = game:GetService("RunService").RenderStepped:Connect()
you placed
updateConnection must be with all variables at the top
2 Likes
Bloxrrey
(aubrey)
March 14, 2021, 6:08am
#14
Oh! My bad. Thanks for the help, it is really appreciated!
2 Likes