What I'm trying to do is make the CurrentCamera for all players to constantly center between all the players in the server who have their playing boolValue checked. (Something similar to a Smash Bros camera during a battle)
local Camera = game.Workspace.CurrentCamera local Player = game.Players:GetChildren() local plr = script.Parent.Parent local Player_T = game.Workspace.Angle repeat wait() until Camera.CFrame Camera.CameraType = Enum.CameraType.Scriptable Camera.CameraSubject = Player_T Camera.CFrame = CFrame.new(Player_T.CFrame.X, Player_T.CFrame.Y, Player_T.CFrame.Z + 30) Camera.FieldOfView = 80 for i = 1, #Player do wait() print(i.." - "..Player[i].Name) end repeat wait() until plr:FindFirstChild("Playing") repeat wait() until plr.Playing.Value == true for i = 1, #Player do Player[i]:WaitForChild("Playing") if Player[i].Playing.Value == true then print(i.." "..Player[i].Name) while Player[i].Character == nil do wait() end while Player[i].Character.UpperTorso == nil do wait(2) end local x = Player[1].Character.UpperTorso.CFrame.X for b = 1, #Player do if Player[b+1] ~= nil then x = x + Player[b+1].Character.UpperTorso.CFrame.X end end x = x * CFrame.new(0.5,0,0) print(x) local Player_Torso = Player[i].Character.UpperTorso local BodyPositioner = Instance.new("BodyPosition", Player_Torso) BodyPositioner.MaxForce = Vector3.new(0, 0, math.huge) BodyPositioner.Position = Vector3.new(0, 0,Player_Torso.Position.Z) ------------------------------------------------------------------- Camera.CameraType = Enum.CameraType.Scriptable Camera.CameraSubject = Player_Torso game:GetService("RunService").RenderStepped:connect(function() Camera.CFrame = CFrame.new(Player_Torso.CFrame.X, Player_Torso.CFrame.Y, Player_Torso.CFrame.Z + 30) Camera.FieldOfView = 80 end) end end
When it get's to line 54, it used to say something else when I tried dividing, So instead I changed it to multiplying by a decimal lower than 1, but then this error came out:
PlayerScripts.LocalScript:54: bad argument #1 to '?' (CFrame expected, got number)
I'm guessing this is saying that I'm trying to multiply the X value by a whole CFrame, but I have no idea how to simplify the CFrame.new into just an X value.
Any ideas or solutions?
shouldn't the average x be all the player's x positions added together then divided by the number of players playing?
local x = 0 for i = 1, #Player do x = x + Player[i].Character.HumanoidRootPart.Position.x end x = x / #Player -- Average X of players playing local BodyPositioner = Instance.new("BodyPosition", Player_Torso) BodyPositioner.MaxForce = Vector3.new(math.huge, 0, math.huge) BodyPositioner.Position = Vector3.new(x, 0,Player_Torso.Position.Z)