Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Spectating script; no output? Please help.

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

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.

4 comments

0

This is in a LocalScript, inside a Textbutton, inside a ScreenGui, inside the StarterGui.

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.

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?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.