How to make player have only a camera?

I want to make a building game, and I made a script to move camera using WASD and rotating it using mouse. But parts around the camera don’t replicate to client. How can I fix this problem? I tried setting ReplicationFocus to camera but I got this error:

Invalid object type for ReplicationFocus property
4 Likes

Player.ReplicationFocus must be set to a BasePart

What you can do is create a part for the replication focus and move it where the camera is every frame or every other frame

1 Like

Once again, you have Roblox staff giving out wrong advice.

but in reality…

1 Like

You will probably have to create a part, that you keep positioned at the camera, so when you move the camera it moves the focus part.

1 Like

Do I have to create part on the server or may it be created on the client side?

1 Like

This answer may be outdated. I don’t think Roblox staff doesn’t know how their own engine workd…

1 Like

I just tried to create one on the client, but it kept telling me the game was paused to load content, so I am assuming you must do it on the server.

1 Like

When that post was made, more than a year ago, it worked fine; you could set ReplicationFocus to any Instance that had a CFrame property. But sometime since then, Roblox did some refactoring of the base classes that parts inherit from, inserting a new abstract class “PVInstance” between Instance and BasePart. It appears that ReplicationFocus now accepts anything that is a “PVInstance”, but that no longer includes the Camera! This is very likely to be an unintentional side effect of the part physics refactoring, and worth reporting as a bug; there is no reason you should need to create a physical Part just to proxy the Camera.CFrame.

EDIT: I’ve filed a bug report for this.

2 Likes

Hello! Can you please provide a working example? I have the following setup, but :InvokeServer() returns nil instead of created part.

-- client
local part = CreatePart:InvokeServer()
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

-- server
function CreatePart.OnServerInvoke(player)
	local part = Instance.new("Part", workspace)
	part:SetNetworkOwner(player)
	player.ReplicationFocus = part
	return part
end

This is just to create the part on the server and for the client to find it.
So all of the camera controls you would need to do yourself.

I have a server script and a client script
image

The server script is…

PlayerData = {}

game.Players.PlayerAdded:Connect(function(player)
	PlayerData[player.UserId] = {}	
	
	local part = Instance.new("Part")
	part.Name = player.UserId
	part.Anchored = true
	part.Parent = workspace

	player.ReplicationFocus = part

	
	if PlayerData[player.UserId] then
		PlayerData[player.UserId].CameraPart = part
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	if PlayerData[player.UserId] then
		if PlayerData[player.UserId].CameraPart then
			PlayerData[player.UserId].CameraPart:Destroy()
		end
	end
	PlayerData[player.UserId] = nil
end)

The client script is…

local player = game.Players.LocalPlayer
local part = workspace:WaitForChild(player.UserId)
print(part)

Thank you, but is there a way to use RemoteFunctions?

You would need a local script that handles the input for the movement of the camera.
In that local script you would move the camera and use a RemoteEvent to send the camera’s coordinates to the server (when the camera moves)
Then the server can update the part, this would probably be more simple because you would not need the client to ever know about the part, only the server.

I don’t think this method is fast enough. Maybe there is a way to enforce part replication?

Why would you need it to be super fast? All the moving of the part is doing is keeping things streamed in.
You could probably send an update every 1 second and it would still be fast enough.

But Remote functions and events are not as fast as replication. My game will contain events other than camera movement and I think there is a cleaner approach.

All I can offer you is how I would do it.

If you can find a more efficient and cleaner way to do this, by all means, go with that solution.
And you can even share your results here for anyone else who might find this post and have the same problems.

I wish you the best.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.