Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to make "RunService.Stepped" Stop?

When I press a button I want it to stop (RunService.Stepped) before doing this you press a button, it makes the camera look at an object and it's working correctly! But if i want the camera to go back to normal, i need to stop Run.Service.Stepped, I Cannot Find anyway of stopping it so far.

function UpdateCam()
	
	local CFam = CFrame.new(script.Parent.Parent.Character.PrimaryPart.CFrame.Position, 		 
        workspace.Dummy.PrimaryPart.CFrame.Position)
	local CamCFam = CFam*CFrame.new(0, 3, 0)
	print(CamCFam)
	workspace.CurrentCamera.CFrame = CamCFam
end

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.L then
		if LisOn == false then	
			LisOn = true
			RunService.Stepped:Connect(UpdateCam)
			
			print("camera changed new")
		elseif LisOn == true then
			LisOn = false
			RunService.Stepped:Disconnect(UpdateCam) -- I want it to be here but this won't work
			
			print("camera changed old")	
		end
	end
end)

3 comments

0

I tried replacing the RunService.Stepped:Disconnect(UpdateCam) into script.parent:destroy() just to test it, it stops the runservice, but if i'm walking and break the script, the walking sound won't stop. And I can't do the same script obviously because i deleted it. still need help!

0

Try removing the UpdateCam on disconnect so it should be like RunService.Stepped:Disconnect()

0

I'm not sure whether that will work

1 answer

✓ Accepted answer

You cannot disconnect events. You can disconnect functions from events by declaring them as variables. In your case, it would be like this:

local stepped = nil -- this is necessary

stepped = RunService.Stepped:Connect(function()

end)

stepped:Disconnect()

7 comments

0

thanks, I figured something out and it works!

0

If my answer solved your problem, then accept it please!

0

radiant_light did my comment work? I haven't scripted in a while

0

also what parameters does :disconnect take? I checked everywhere, i couldn't find any source

0

i'll accept your answer as soon as i get a response.

0

It doesn't take any arguments. It can only be called on connected functions. Also JesseSong, that wouldn't have worked since you can't disconnect events. xP

0

ah ok, just double checking. anyways i accepted your answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.