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

Spectating script; no output? Please help.

Asked by 10 years ago

I have a spectating script I made, but after you click on it it just says "close" but nothing else works? Here's the script:

local camera = game.Workspace.CurrentCamera
local on = false
script.Parent.MouseButton1Down:connect(function()
    if on == false then
        for i,v in pairs(game.Players:GetPlayers()) do
            if v.InGame.Value == true then
                camera.CameraType = "Attach" 
                camera.CameraSubject = v.Character.Head
                script.Parent.Text = "Close"
                game.Players.LocalPlayer.PlayerGui.timer.Frame.Visible = false
                game.Players.LocalPlayer.PlayerGui.tp.TextButton.Visible = false
                game.Players.LocalPlayer.PlayerGui.spect.Frame.Visible = true
                on = true
            end
        end
    end

    if on == true then
        game.Players.LocalPlayer.PlayerGui.timer.Frame.Visible = true
        game.Players.LocalPlayer.PlayerGui.tp.TextButton.Visible = true
        game.Players.LocalPlayer.PlayerGui.spect.Frame.Visible = false
        camera.CameraType = "Custom"
        camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    end
end)

1 answer

Log in to vote
0
Answered by
jav2612 180
10 years ago

This needs to be a local script in a player or character in order to get game.Workspace.CurrentCamera.

Based on the for i,v in pairs(game.Players:GetPlayers()) do It appears your trying to do this for every player, but you're only using 1 camera.

Try making this a local script in a Player, and have this script so that you can do this to LocalPlayers separately.

0
This is in a LocalScript, inside a Textbutton, inside a ScreenGui, inside the StarterGui. systematicaddict 295 — 10y
0
Well like I said, you're trying to change one person's camera to every player's head, and it just keeps getting changed as the loop goes through all the players. Your going to need to pick 1 player to change the camera to accordingly and maybe make it so the players can scroll through them to spectate. jav2612 180 — 10y
0
How would I make it go through one player at a time? I know how to make it pick a random player, but how can I make it scroll through? systematicaddict 295 — 10y
0
If I were you, I would put everyone that is spectatable into a table, and then when the person clicks a button or something it will go through that table and spectate that specific person. jav2612 180 — 10y
Ad

Answer this question