Client/Server issues

Hi guys, so I’m currently making an FPS game based on WWI, but I’m having some slight issues - one in particular really baffles me. Here it goes:

There is a module in Replicated Storage that handles camera events for each player. (e,g. resetting the menu camera every time a player dies.) Now, this works only half of the time, for whatever reason. (I don’t think there are any issues with my function, but I’ll send it anyways.) A script in ServerScriptService calls on that module each time a player dies. It doesn’t need to list the name of the player that player because the module is placed in a local environment, and can use CurrentCamera. For some reason, when I call on the module to reset the camera to be in menu mode, it doesn’t work, and the camera doesn’t change. This seems ironic because my other script (also in ServerScriptService) calls on the same module (though it calls on a different function, the module still uses CurrentCamera) and it works. This scripts responds to a remote event that is fired by the client, so that may have something to do with it. Anyways, here’s a diagram of my workspace for you visual learners:

image

local CameraFunctions = {}

CameraFunctions.SetMenuCam = function()
	wait()
	print("Setting up Menu Cam...")
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	game.Workspace.CurrentCamera.CFrame = CFrame.new(-1.80671906, 19.4002342, 54.1632576, 0.845210075, 0.202657416, -0.49451983, -0, 0.925314784, 0.379199982, 0.53443414, -0.320503652, 0.782085419)
	game.Workspace.CurrentCamera.CameraSubject = nil
end

CameraFunctions.AttachToPlayer = function(Humanoid)
	print("Attaching Camera To Player...")
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	game.Workspace.CurrentCamera.CameraSubject = Humanoid
end

return CameraFunctions

image
Code for ServerMenuManager:

CamS = require(game.ReplicatedStorage.Modules.CameraFunctions)
MenuGui = game.ReplicatedStorage.GUIs.MenuGui
CameraEvent = game.ReplicatedStorage.Events.SetCamera
local respawnDelay = 5
game.Players.PlayerAdded:connect(function(player)
	print("Setting Menu Cam...")
	CamS.SetMenuCam()
	print("done")
	MenuGui:Clone().Parent = player.PlayerGui
	player.CharacterAdded:connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		if humanoid then
			humanoid.Died:connect(function()
					wait(respawnDelay)
					CamS.SetMenuCam()
					MenuGui:Clone().Parent = player.PlayerGui
			end)
		end
	end)
end)

Code for Deploy button:

game.ReplicatedStorage.Events.Deploy.OnServerEvent:connect(function(player)
	local CamS = require(game.ReplicatedStorage.Modules.CameraFunctions)
	--MainGui = script.Parent.Parent.Parent
	print("Server Responding...")
	player:LoadCharacter()
	repeat wait() until player.Character
	CamS.AttachToPlayer(player.Character.Humanoid)
	print("Server Responded.")
end)

Hopefully someone can give me a hand! I’m quite confused at the moment unfortunately.

Link to place: Western Front - Roblox

For future reference, you can use the ‘Development Support’ Channels for this kind of query :slight_smile:

1 Like

You can move this thread by clicking the edit button.

My bad, I clicked the wrong one. Any ideas though?

Why are you manipulating the camera server end?

I’m calling on a locally-stored module to manipulate the camera, not from a server-sided module.

But a server script is requiring the module from what I can see in your included code. When a server script requires a module (even if stored locally, eg replicated storage) it runs as a server script.

Good to know… So why does it work when I call on it with the Deploy script?

Not sure, send output logs.

Try making sure that Players.CharacterAutoLoads is off if it isn’t already.

top line in server output is just a ragdoll script that’s made really badly.

This all works in studio, btw, so I know it has to be some kind of a client-server issue

Modules required by server scripts will run as server scripts. Modules required by local scripts will run as client scripts. Even though your module is in a client location, since it its being called by the server, it is a server script – since it is a server script, it is manipulating their server’s CurrentCamera and not the client’s. It works in Play Solo because the client/server are the same.

To resolve this issue, you will need to have the server script fire a remote event which a local script responds to by calling the module. This way even though the server is triggering the action, the module is being required by the client and is running in the client context.

1 Like

Echo is correct, I thought you were inferring that it worked in a normal server.

Welp thanks echo for deleting.

The reason this is working for you in studio is the client is running with server permissions. In a normal game this wouldn’t work because think about it, how would roblox know who’s camera needs to be changed if it’s server end.

If you want to control the players camera from the server, you can fire a remote event to the player to change their camera, then the client requires the local module.

1 Like

What do you mean? The output I sent you was from a normal server

Sorry, I accidentally pressed the delete button on mobile.

The reason it’s “working” is you are calling load character which would reset the players camera. The server isn’t actually changing the players camera.

edit for typo

If this helped you mark it as a solution so others with this problem can find out how to fix it easily.

Thanks. I’ll get back to you once I try applying this stuff.

1 Like