Good Day! , I am currently having a weird annoying bug. Its a bug that should not happen and only god knows why it happens. I coded a camera system (client module script) for my game which is a harmless and basic script. It only have two main function, SetCameraToParts and SetCameraToPlayer.
SetCameraToParts work perfectly fine, the problem is SetCameraToPlayer
The Script :
-------------------
--SERVICES
local PlayerService = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Camera = workspace.CurrentCamera
-------------------
--INSTANCE/VARIABLE
local CameraParts = workspace:WaitForChild("CameraPart")
local LocalPlayer = game:GetService("Players").LocalPlayer
local LocalMouse = LocalPlayer:GetMouse()
local SystemModule = ReplicatedStorage:WaitForChild("SystemModule")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Functions = {["IsActive"] = Remotes:WaitForChild("Functions"):WaitForChild("IsActive")}
local ModuleHandler = require(SystemModule:WaitForChild("ModuleHandler"))
local CameraSystem = {}
local Modules = {}
------------
--MAIN CODE
-->> INITIALIZATION
function CameraSystem:Init()
--MODULES
Modules["PlayerModule"] = ModuleHandler:GetSystem("PlayerSystem")
--MAIN INIT()
repeat
task.wait()
until Camera.CameraType ~= Enum.CameraType.Fixed
Camera.CameraType = Enum.CameraType.Scriptable
self:SetCameraToPart("MainMenu")
return true
end
-- >> FUNCTIONS
function CameraSystem:SetCameraToPart(PartName : string)
RunService:UnbindFromRenderStep("PlayerCamera")
if Camera.CameraType ~= Enum.CameraType.Scriptable then
print("Camera Failed to Set")
return
end
if CameraParts:FindFirstChild(PartName) or CameraParts:WaitForChild(PartName) then
local Part = CameraParts[PartName]
Camera.CFrame = Part.CFrame
end
end
-------------------------------
local TargetCam : BasePart
local function PlayerCamera()
if not TargetCam then
return
end
--MAIN FUNCTIONALITY
Camera.CFrame = CFrame.new(TargetCam.Position + Vector3.new(0,50,0),TargetCam.Position) --This breaks
TargetCam.CFrame = CFrame.lookAt(TargetCam.Position, Vector3.new(LocalMouse.Hit.Position.X,TargetCam.Position.Y,LocalMouse.Hit.Position.Z))
end
function CameraSystem:SetCameraToPlayer()
local Character = Modules["PlayerModule"]:GetCharacter()
TargetCam = Character:FindFirstChild("HumanoidRootPart")
RunService:BindToRenderStep("PlayerCamera",Enum.RenderPriority.Camera.Value,PlayerCamera)
end
return CameraSystem
(Im very new to modular coding so bare with me)
As you can see i have this specific line that seems harmless
Camera.CFrame = CFrame.new(TargetCam.Position + Vector3.new(0,50,0),TargetCam.Position)
For some weird reason, whenever i have this line of code enabled, when a player goes to a specific Y level or above, it instantly kills and make the player dissapear (?) when i make this line a comment, everything seems to be working fine. What could possible be wrong with this line of code? Also i do not have a anti-cheat system for this to happen nor have i put any free model in my game.
Video Context :
The Kill In the beginning is not the bug
SetCameraToPlayer function is only called when the player chose a class and click Play and when the player click respawn (thats why you can see player still alive before respawn button is clicked)
This only happens in high Y level , if the player is on the ground it works perfectly fine, but if player get too high it dies ??? (thats why the spawnpoint and the game spawn is on the sky)
Thank you for your time reading! , iād greatly appreciate if you can help me debug this!