I'm making a spectate option for my game, I need it to return the camera to a part?
So, this is what I'm trying to make. I'm making a option where you click on the player to spectate them. It works fine, but my game uses camera manipulation, so the camera is fixed to the part until they choose their team. When you stop spectating a player it returns your camera to the normal camera. I need it to return the camera back to the part that I am using. I'm sorry the script is soo long, I've tried modifying parts of it, but I couldn't find what I need to change. Any help will be appreciated, thanks!
02 | while not script.GUI.Value do wait() end |
05 | player = playergui.Parent |
06 | while not player:FindFirstChild( "Backpack" ) do wait() end |
07 | backpack = player.Backpack |
09 | while not player.Character do wait() end wait() |
14 | function stopWatching() |
15 | local cam = workspace.CurrentCamera |
16 | cam.CameraSubject = player.Character.Humanoid |
17 | cam.CameraType = "Custom" |
22 | window.Visible = false |
23 | if not plr.Character then return end |
24 | local human = plr.Character.Humanoid |
25 | if not human then return end |
26 | local cam = workspace.CurrentCamera |
27 | cam.CameraSubject = human |
28 | cam.CameraType = "Custom" |
29 | human.Died:connect( function () |
30 | if watching = = plr then wait( 3 ) stopWatching() end |
35 | player.Character.Humanoid.Died:connect( function () stopWatching() watch = function () end end ) |
36 | gui.Changed:connect( function (p) |
37 | if p = = "Parent" and not gui.Parent then |
43 | if not window.Visible then return end |
44 | frame:ClearAllChildren() |
45 | local fw = window.Frame.AbsoluteSize.X - 10 |
46 | local fh = window.Frame.AbsoluteSize.Y - 10 |
49 | local cols = math.floor(fw / (bw + 10 )) |
50 | local rows = math.floor(fh / (bh + 10 )) |
52 | local players = game.Players:GetChildren() |
53 | for k, v in pairs (players) do if v = = player then table.remove(players, k) end end |
57 | for i = 1 , #players do |
58 | local plr = players [ i ] |
59 | local b = Instance.new( "ImageButton" , frame) |
61 | b.Size = UDim 2. new( 0 , bw, 0 , bh) |
62 | b.Position = UDim 2. new( 0 , 5 + col * (bh + 10 ), 0 , 5 + row * (bw + 10 )) |
63 | b.AutoButtonColor = true |
64 | b.BackgroundColor 3 = Color 3. new( 0 , 0 , 0 ) |
65 | local l = Instance.new( "TextLabel" , b) |
66 | l.Position = UDim 2. new( 0.5 , 0 , 0.5 , 0 ) |
70 | l.TextColor 3 = Color 3. new( 1 , 1 , 1 ) |
71 | if plr.Character:FindFirstChild( "Survival" ) then |
72 | l.TextColor 3 = Color 3. new( 1 , . 8 , . 8 ) |
74 | l.TextStrokeColor 3 = Color 3. new( 0 , 0 , 0 ) |
75 | l.TextStrokeTransparency = 0 |
76 | b.BorderColor 3 = Color 3. new( 1 , 1 , 1 ) |
77 | b.MouseButton 1 Down:connect( function () |
81 | if col > cols then col = 0 ; row = row + 1 end |
88 | gui.TextButtonMain.MouseButton 1 Down:connect( function () |
92 | window.Visible = not window.Visible |