Camera doesnt change CameraType if UIS are cloned

I have a script, which parents the Screen GUIs to Player Gui, because I disabled CharacterAutoLoads. I have been using this until I started the game with 2 players and realized the GUIs will only be visible for the first player. This is how it worked:

Script:

local ius = game.StarterGui:GetChildren()
       
for _, v in ipairs(ius) do
                
       v.Parent = player.PlayerGui
                
end

Video:


After adding “Clone()”

Script:

local ius = game.StarterGui:GetChildren()
       
for _, v in ipairs(ius) do
                
       v:Clone().Parent = player.PlayerGui
                
end

The script is inside a CharacterAdded function with the rest of the code which changes some GUI properties, the only thing that doesnt work there is the camera change.

It would be nice to see other context like other code snippets or console. Are you sure the character is properly being spawned?

From what I can see from the examples, both cases seems to fire the deploy:31 line, but only the first example triggers a line in Script:8. Would this be an issue?

1 Like

Thank you for your answer. There is no error or anything in the console. The “deploy:31” prints the character that the player will use and yes, it spawns and the “script:8” its not related to this, its a bombing system that starts at random and just started faster than the second one. I think I found the error. It may be that when I clone the Screen Gui, Im doing it from the server so the lines about the camara wouldn’t take effect, because the server doesnt recognize the player’s camera.

To avoid headaches in the future, LocalScripts under PlayerScripts (from StarterPlayerScripts) will still run without having to spawn a character. I would recommend cloning your gui from there.

1 Like

I did it, but the UI still doesnt work properly, I dont know why.

Again, that’s something we cant figure out if you fail to provide other snippets.

Try setting the camera back to the humanoid using something like this:

camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = pathToHumanoid

I printed the camera, camera type and camera subject before and after changing the camera properties, somehow the camera type is set on custom, when is on scriptable and the camera subject is the humanoid
image
(the blue thing its before and the red one its after)

Sorry, here is the rest of the characteradded function:

game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
                
      print(workspace.CurrentCamera)
      print(workspace.CurrentCamera.CameraType)
      print(workspace.CurrentCamera.CameraSubject)
                
      workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
      workspace.CurrentCamera.CameraSubject = char
                
      print(workspace.CurrentCamera)
      print(workspace.CurrentCamera.CameraType)
      print(workspace.CurrentCamera.CameraSubject)
                
      script.Parent.Parent.Parent.Visible = false
                
      local captures = script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Capture"):GetChildren()
                
      for _, i in ipairs(captures) do
                        
               if i.Name ~= "aviso" then
                        i.Visible = true
               end
                        
     end
                
     if workspace.E.Capturado.Value == false then
                script.Parent.Parent.Parent.Parent.Parent.Capture.mapa.Text = "Mannerheim Line: Main Line of Defense, Summakulä"
     elseif workspace.D.Capturado.Value == false then
                script.Parent.Parent.Parent.Parent.Parent.Capture.mapa.Text = "Mannerheim Line: Artillery Positions"
     elseif workspace.C.Capturado.Value == false then
                script.Parent.Parent.Parent.Parent.Parent.Capture.mapa.Text = "Mannerheim Line: Defensive Position SK10"
      elseif workspace.B.Capturado.Value == false then
                script.Parent.Parent.Parent.Parent.Parent.Capture.mapa.Text = "Mannerheim Line: Supply Station"
      elseif workspace.A.Capturado.Value == false then
                script.Parent.Parent.Parent.Parent.Parent.Capture.mapa.Text = "Mannerheim Line: Main Defensive Bunker SK18"
       end
                
end)

(I know its not very optimized, sorry)

here its the menu:


and here its the player’s character:
image

Although messy, it seems fine. What about your menu camera code? Are you properly disconnecting/destroying whatever is handling the menu camera movement?

I dont find anything that can make the system dont work, here’s the script:

local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera

cam.CameraType = Enum.CameraType.Scriptable

local mouse = player:GetMouse()

local maxTilt = 10
game:GetService("RunService").RenderStepped:Connect(function()
        
        if cam.CameraType == Enum.CameraType.Custom or player.Character ~= nil then
                cam.CameraType = Enum.CameraType.Custom
                cam.CameraSubject = player.Character.Humanoid
        end
        cam.CFrame = workspace.Cam.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)

I added the “or player.Character…” but again didnt work

edit: forgot to re-add the “return”

seems that was the problem, now the camera its OK, just i need to figure out why the team GUI its visible. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.