player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
humanoid.AutoRotate = false
local cameraAngleX = 0
local cameraAngleY = 0
local function playerInput(actionName, inputState, inputObject)
-- Calculate camera/player rotation on input change
print("input change")
if inputState == Enum.UserInputState.Change then
cameraAngleX = cameraAngleX - inputObject.Delta.X
-- Reduce vertical mouse/touch sensitivity and clamp vertical axis
cameraAngleY = math.clamp(cameraAngleY-inputObject.Delta.Y*0.4, -75, 75)
-- Rotate root part CFrame by X delta
rootPart.CFrame = rootPart.CFrame * CFrame.Angles(0, math.rad(-inputObject.Delta.X), 0)
end
end
ContextActionService:BindAction("PlayerInput", playerInput, false, Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
RunService.RenderStepped:Connect(function()
if camera.CameraType ~= Enum.CameraType.Scriptable then
camera.CameraType = Enum.CameraType.Scriptable
end
local startCFrame = CFrame.new((rootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, cameraOffset.Z))
local cameraFocus = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, -10000))
camera.CFrame = CFrame.new(cameraCFrame.Position, cameraFocus.Position)
print("Parent", script.Parent, "CFrame", rootPart.CFrame.Position)
end)
end)
This is some code taking from the Roblox Dev Article https://developer.roblox.com/en-us/articles/Camera-manipulation in the "Over the Shoulder" section.
playerInput should fire everytime the mouse is moving, printing "Input Changed" Renderstepped should fire every frame, printing the player's position.
This code works usually, but when the player dies, a new RenderStepped starting printing the respawned player's position, but it seems as if the old one is still printing the player's position before it died. (See below)
Output:
input change
Parent PlayerScripts CFrame -113.862038, 2.97397137, -88.958931
Parent PlayerScripts CFrame -26.2728577, -509.415833, -313.633331
input change
Parent PlayerScripts CFrame -114.072174, 2.97397137, -89.1231079
Parent PlayerScripts CFrame -26.2728577, -509.415833, -313.633331
As you can see, the first line of each block is inputChange from me moving my mouse.
The second line is the player's new position after they respawn. This changes as I move the player.
The third line is the player's position right before it died. Here, it seems like two instances of RenderedStep is running.
Can anyone explain why?

1 comment
You never disconnect the connection