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:
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.
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
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)
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.
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.
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.