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