I am working on a game which has FilteringEnabled active, when the player joins their chracter is moved to another location by changing the torsos CFrame. When the player is teleported the game seems to break, on the clients screen the player has not moved however on the server the player is moved, after this happens any movements on the client are not registered by the server.
Here is a screenshot with annotations to help you understand:
https://gyazo.com/04e589b278cd8b628d703bbd32119f7b
As you can see the locations are different and there is no output other that the print from my code.
Here is the serverside code:
game.Players.PlayerAdded:connect(function(player)-- Player added print(player.Name ..tostring(" has joined!")) -- Print player name player.CharacterAdded:connect(function(character)-- When the players character has been added print("Character Added") local torso = character:FindFirstChild("Torso") local camscript = script.CameraScript:Clone() camscript.Parent = character local RF = camscript.CamRF if torso then-- Run if the torso is found repeat wait() until torso.CFrame -- Wait for the torsos CFrame to load print("Torso Found, attempting to move character") torso.CFrame = CFrame.new(game.Workspace.Pod1.Podbase.Position) + Vector3.new(0, 4.5, 0) torso.Anchored = true character.Humanoid.PlatformStand = true print("Character moved") RF:InvokeClient(player, "cam1") end end) end)
The clientside code is inside the character in workspace and it only freezes the camera when the remote function is invoked.
Here is the client code:
local RF = script:FindFirstChild("CamRF") local character = script.Parent local head = character:FindFirstChild("Head") repeat wait() until RF function RF.OnClientInvoke(message) if message == "cam1" and head then local cam = game.Workspace.CurrentCamera cam.CameraSubject = head cam.CameraType = "Scriptable" local pos = head.Position + Vector3.new(-5, 1, -10) local targ = head.Position + Vector3.new(-6, -1, 0) cam.CoordinateFrame = CFrame.new(pos, targ) end end
-EDIT-
Just noticed this in outupt:
13:01:08.517 - Replication: Can't create default object of type Players
which has been posted about before:
http://forum.roblox.com/Forum/ShowPost.aspx?PostID=161850098
However this does not happen if I disable the script so I still think its my code which is the problem.
I suggest changing some ways of how your code is. I'll give the slightly manipulated code bellow with what I changed under it.
game.Players.PlayerAdded:connect(function(player)-- Player added print(player.Name ." has joined!") -- Print player name player.CharacterAdded:connect(function(character)-- When the players character has been added print("Character Added") local torso = character:WaitForChild("Torso") local camscript = script.CameraScript:Clone() camscript.Parent = character local RF = camscript.CamRF if torso then-- Run if the torso is found print("Torso Found, attempting to move character") torso.CFrame = CFrame.new(game.Workspace.Pod1.Podbase.Position) + Vector3.new(0, 4.5, 0) torso.Anchored = true character.Humanoid.PlatformStand = true print("Character moved") RF:InvokeClient(player, "cam1") end end) end)
All I did here was remove tostring for your first print and made all FindFirstChild()'s
into WaitForChild
, No matter what a Torso must exist unless you do something to the Character so why use findfirstchild and risk getting nil? Also, I removed your waiting for CFrame, I do not believe you will ever need to do that. I have never had a problem with CFrame not existing. If the part is there, I feel that the CFrame should be existent as well
local RF = script:WaitForChild("CamRF") local character = script.Parent local head = character:WaitForChild("Head") function RF.OnClientInvoke(message) if message == "cam1" and head then local cam = game.Workspace.CurrentCamera cam.CameraSubject = head cam.CameraType = "Scriptable" local pos = head.Position + Vector3.new(-5, 1, -10) local targ = head.Position + Vector3.new(-6, -1, 0) cam.CoordinateFrame = CFrame.new(pos, targ) end end
What I did for the above code is remove your wait for CamRF to exist, using WaitForChild will do basically the same exact thing; yield the script until it is found. I also added WaitForChild to you head variable.
Btw, 13:01:08.517 - Replication: Can't create default object of type Players is in every game on ROBLOX, I would ignore it. It's ROBLOX's fault not ours and I haven't noticed it effect anything either.