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

Spectate Script Help Broken?(SOLVED)

How do I make a spectator tool to view different players? I have no idea how to do this. This is my attempt:

function onSelected(tool)
game.Players.LocalPlayer
function Camera = "Spectate"
Camera.Position.Vector3.new(0,0,0)
end
end
end

This is what I tried. It didn't work. Someone please help me fix it so it will let players spectate other players.

2 comments

0

What are you trying to do with the 'game.Players.LocalPlayer' line? It seems to be strange.

0

I have no knowledge using Camera commands. I tried my best :c

1 answer

✓ Accepted answer

What does that mean? You can't create a variable "function" and assign to it a string value, that absolutely make sense, if you want to do something with enums, I suggest you to create a Script that stores camera's enums like this:

local enums { "Spectate", "First Person", "Third Person" }

_G.storeEnums = function(par1)
	for _, v in pairs (par1) do
		if not game.YourPathStorage:FindFirstChild(v) then
			local par2 = Instance.new("StringValue", game.YourPathStorage)
			par2.Name = v
			if v == "First Person" then
				par2.Value = true -- the camera initialized is First Person
			end
		end
	end
end

Call that function where you want, I suggest you on ServerStart.

And then create a getter function (if you want) for fast access, from that you call what type of enum you need for your camera:

function getActivatedEnum()
	local enums = game.YourPathStorage:GetChildren()
	for _, v in pairs (enums) do
		if game.YourPathStorage:FindFirstChild(v).Value == true then
			return v -- return the activated enum
		end
	end
end

function setActivatedEnum(par1)
	local enums = game.YourPathStorage:GetChildren()
	local par2 = game.YourPathStorage:FindFirstChild(par1)
	for _, v in pairs (enums) do
		local par3 = game.YourPathStorage:FindFirstChild(v)
		par3.Value = false
	end
	par2.Value = true -- activate the enum in passed as the argument "par1"
end

function changeCamera()
	local camera = getActivatedEnum()
	if camera== "First Person" then -- if the camera name is 'First Person'....
		setActivatedEnum("Spectate") -- disable all of the enums except the requested on, in this case it's "Spectate"
	end
end

That's an advanced Enum System by me, it works because I use it :P

2 comments

0

How would I use this, so that when the player(s) are in the lobby, they can use this. And not during the game?

0

Just load it on "PlayerAdded" ._.

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