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

This is supposed to change the camera for all players, but it doesn't work?

This is supposed to change the camera for all players, but it doesn't work? help? It's not a localscript!

function CameraChange()
	local Camera = game.Workspace.CurrentCamera
	local Players = game.Players:GetChildren()
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = game.Workspace.Cameras.MenuCam.CFrame
	end

3 comments

0

For one thing, workspace.CurrentCamera is inaccessible to non-local scripts. Hence, any code that manipulates a client's camera must be done in a local script.

0

@MightyBaconOverload Soooo, How would I go along fixing this.

0

The best way to go about this is by using a RemoteEvent. A server script would fire the event whenever it wants to change the player cameras. Each client would listen to this event and run the camera manipulating code whenever the event is fired by the server.

1 answer

✓ Accepted answer

The only way to properly do this would be remote events.

Client Script:

game.Workspace.RemoteEvent.OnClientEvent:connect(function(func, ...)
	if func == "Camera" then
		local Camera = game.Workspace.CurrentCamera
		local Players = game.Players:GetChildren()
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = game.Workspace.Cameras.MenuCam.CFrame	
	end
end)

Server Script:

game.Players.PlayerAdded:connect(function(plr)
	game.Workspace.RemoteEvent:FireClient(plr, "Camera")
end)

or just

game.Workspace.RemoteEvent:FireAllClients("Camera")

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