I am currently working on a menu for my game and I have experienced some bugs.
When ever you press my deploy button the camera is suppose to change from scriptable to custom and the players camera should start following the players character.
But instead the camera changes to scriptable, why is this happening?
local player = game:GetService('Players').LocalPlayer
local mouse = player:GetMouse()
local run = game:GetService('RunService')
local cp = workspace:WaitForChild('Cam')
local cam = workspace.CurrentCamera
local maxDegree = math.rad(45)
repeat
cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable
run.RenderStepped:Connect(function()
if player.Team == game:GetService('Teams'):WaitForChild('Lobby') then
local mp = Vector2.new(mouse.X, mouse.Y)
local centre = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
local difference = mp - 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
end)
local frame = script.Parent:FindFirstChild('Frame')
local deploy = frame:FindFirstChild('Deploy')
local event = game:GetService('ReplicatedStorage'):WaitForChild('Spawn')
deploy.Activated:Connect(function()
print('Deploying')
cam.CameraType = Enum.CameraType.Custom
print(cam.CameraType)
event:FireServer()
wait(1)
repeat
cam.CameraSubject = player.Character:FindFirstChild('Humanoid')
print(cam.CameraType)
local cframe = CFrame.new(player.Character:FindFirstChild('Head').Position)
cam.CFrame = cframe
cam.CameraType = Enum.CameraType.Custom
until cam.CameraType == Enum.CameraType.Custom
print('Camera changed')
end)
Thanks for the help
Also please note that this is my first post and I have like no idea what I’m doing so if you have any tips they are much appreciated