Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

CameraSubject not working?

Asked by 8 years ago

I've created a spectating GUI, and when pressed you view one of the living players(one of the players in-game.) This script works perfectly, except for when a player joins the server and the game is in progress. When they press the button, their CameraSubject is no longer focused on their humanoid, but it's focused on where it used to be. It does not start 'spectating' a different player as intended. If the round ends and they end up back in the lobby(after dying,) the script works absolutely flawlessly. It's worth noting that it never throws out any errors of any kind. Here's what the code looks like, I tried to put enough information in there for you to get the just:

local plr = game.Players.LocalPlayer
local debounce = false
repeat wait() until plr:FindFirstChild("Alive")--Make sure they have the "alive" boolean
repeat wait() until plr.Character--Make sure they are in Workspace
wait(.05)--Little extra waiting time
local camera = game.Workspace.CurrentCamera 
script.Parent.MouseButton1Click:connect(function()--Gui pressed
    if plr.PlayerGui.Spectating.Frame.Visible == false then --If they aren't already spectating
            if plr.Alive.Value == false and game.Workspace.InRound.Value == true then --If they're dead and there's a game going
        plr.PlayerGui.Spectating.Frame.Visible = true--Make spectating Gui visible
    if game.Workspace.InRound.Value == true then--Double check
if debounce == false then
    debounce = true
    local plrs = game.Players:GetChildren()
    local num = #plrs
    local found = false
    local plays = {}
    for _,i in pairs(plrs) do
        if i.Alive.Value == true then
            table.insert(plays, 1, i.Name)--Fancy stuff to make the spectating Gui work properly
        end
    end
    local nums = game.Players.LocalPlayer.PlayerGui.Spectating.Frame:FindFirstChild("Numb")
    local spec = game.Players:FindFirstChild(plays[nums.Value])
    nums.Value = nums.Value + 1
if nums.Value > #plays then nums.Value = 1 end
camera.CameraSubject = spec.Character.Humanoid--Changing CameraSubject
local who = plr.PlayerGui.Spectating.Frame:FindFirstChild("Who")
 local job = plr.PlayerGui.Spectating.Frame:FindFirstChild("Job")
local pic = plr.PlayerGui.Spectating.Frame:FindFirstChild("Pic")
who.Text = ""..spec.Name..""
pic.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..spec.Name..""
if spec.IsMafia.Value == true then
    job.Text = "Mafia"
    else job.Text = "Innocent"
end
    debounce = false
end
    end
    end
    else plr.PlayerGui.Spectating.Frame.Visible = false
        camera.CameraSubject = plr.Character.Humanoid
    end
end)
0
I recommend looking up proper indentation style (if you don't use it already -- you did imply this might be an abbreviation of your script) - it makes it easier to see the flow of your script. and catch logic errors. In your case, did you set the SpectatingFrame to Visible in a different script? chess123mate 5873 — 8y
0
To put it simply, yes I do use proper indentation style, but I was rushing this when I posted the first time. The Spectating Frame is indeed made visible, it just doesn't make the CameraSubject the proper player. It shows their name, and even shows a picture of their avatar, but doesn't switch the CameraSubject(only when player first joins game...) Toadboyblue 67 — 8y

Answer this question