How Do i Get this RenderStepped Loop To Stop When the player Respawns [solved]

Here is the code i will tell you what i want below sorry if it’s hard to read this is how i always code i will likely understand your guys responses because I’m Skill coder

local PlrCam = workspace.CurrentCamera
PlrCam.CameraType = Enum.CameraType.Scriptable

game.ReplicatedStorage.RemoteEvents.Atc.OnClientEvent:Connect(function()
PlrCam.FieldOfView = PlrCam.FieldOfView
local Lock = game:GetService(“RunService”).RenderStepped:Connect(function(Lock)
PlrCam.CFrame = game.Workspace:FindFirstChild(" ").View.CFrame
–Lock:Disconnect() –
end)
end)

all that happens when i try to disconnect the Loop is a huge lag spike that crashes studios this script is located in starterplayerscripts and its for a horror game
that I’ve been asked to code i suppose ending the loop will reset the players camera back to default “correct me if I’m wrong” this is my goal for the code

(i do not understand rendering)
(edit: i just researched what it is, i found out its just a loop, got it)

also can you explain your main goal with some clarity?

but a recommendation is to do

game.Players.PlayerAdded:Connect(function(plr)
--do whatever when the player joins
plr.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
--do what ever :scream:, probs Lock:Disconnect() here ig
end)
end)
end)

This is all what you need to know:

local RS = game:GetService("RunService")

-- Declare a name for your function, acts like an identifier.
local function_name = "F1"
-- Function here
local function f1()
	-- Your function goes here
end

-- Instead of RS.RenderStepped:Connect(func), use this
RS:BindToRenderStep(function_name, Enum.RenderPriority.First.Value, f1) -- edit args 1 & 2 to your liking
-- Later, unbind this function using the name we set
RS:UnbindFromRenderStep(function_name)
1 Like

oh, thank you for teaching me and helping me understand more

If you want to learn more about what the 2nd argument in BindToRenderStep is, check this out.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.