I have a script for mobile players that gives them a custom shiftlock that makes the camera go up their head a bit and aim at the center thru an offset, but in my game’s character changing systems, it adds onto the offset and slowly rises up infinitely
When the character dies, and respawns the camera goes back into the intended position/look
So it has to be related to the character changing systems or it just adds onto the previous camera position leading to the addition with the offset
Logically the camera should reset with each character change because im destroying the character, when the character dies, the player is sent into a box without the “Playing” tag and when they press play, their custom character is loaded with the tag; So the character creation should reset it
Unless you have logic elsewhere to check when a player dies, this will not properly unbind the function, so the onStep() function will keep running and begin stacking every time the player spawns a new character. Instead of (0, 1.5, 0) being added to the offset every frame, it becomes (0, 3, 0) and so on.
This is because this block of code, connected to the CharacterAdded signal, only runs once - when the character first spawns. In order to detect when this character has been removed during respawn, you can use AncestryChanged to trigger the UnbindFromRenderStep().
Example:
game:GetService("Players").LocalPlayer.CharacterAdded:Connect(function(char)
if char:HasTag("Playing") then
RunService:BindToRenderStep("Mobile/ConsoleShiftLock",Enum.RenderPriority.Camera.Value,OnStep)
end
local characterRemovedConnection: RBXScriptConnection
characterRemovedConnection = char.AncestryChanged:Connect(function(_, newParent)
if newParent == nil then -- the character has been removed and no longer has a parent.
characterRemovedConnection:Disconnect() -- dispose of this connection variable
characterRemovedConnection = nil
-- and unbind the function!
RunService:UnbindFromRenderStep("Mobile/ConsoleShiftLock")
end
end)
end)