i was trying to make a top view camera controller of some sort and uhhhhhhh
it does this when i tab out and tab back in, i have no idea why
basically it dosent let me walk anymore and just walks in random directions, this is not related to the mouse rotation since it appeared way before i made that system, but originally i thought this was a studio only bug since it didnt appear in the main game
does anyone have any idea why this is happening? here is the code i use for the camera:
local Camera = workspace.CurrentCamera
local RS = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local CamDelay = 0.2
local Mouse = game.Players.LocalPlayer:GetMouse()
Camera.CameraType = Enum.CameraType.Scriptable
function camsway()
while true do
task.wait()
local HRP = Char:FindFirstChild("HumanoidRootPart")
TweenService:Create(Camera, TweenInfo.new(CamDelay),{CFrame = CFrame.new(HRP.Position.X,HRP.Position.Y,HRP.Position.Z)*CFrame.new(0,45,0)*CFrame.Angles(math.rad(-90),math.rad(0),math.rad(0))}):Play()
end
end
task.spawn(camsway)
RS.Heartbeat:Connect(function()
local HRP = Char:FindFirstChild("HumanoidRootPart")
HRP.CFrame = CFrame.new(HRP.Position, Vector3.new(Mouse.Hit.Position.X, HRP.Position.Y, Mouse.Hit.Position.Z))
end)
i dont have any idea why this is happening or what to even try to fix this, please help
You’re setting the character’s HumanoidRootPartCFrame as the Mouse.Hit position at the end of your script. If the camera is linked to your Character, what happens is that when you set the Character position, you move the Camera too, moving the mouse position as well, creating an infinite loop.
To fix this, you can simply disconnect the camera from the character by setting its CameraFocus and CameraSubject properties, as well as the CameraType.
This should not be a reason to not use RenderStepped at all. Both RenderStepped and Heartbeat run every frame. If your goal is to crack down on FPS unlocker abuse, you will need to take a different approach.
@ilGravi I believe your approach won’t do what you may be anticipating. The footage shows that the camera is already detached from the player’s character. Even if the camera was attached to the player, this would make no difference as only the rotation is being set, not the position.
Try using RenderStepped or BindToRenderStep. It will most likely solve your problem.
it actually did! i was using a normal loop here because i wanted to add some fallback to the camera, but it caused some issues so i’ll use this until i find a better way. thank you for your help!!