Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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)
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! superbubba2020 6 — 3y
0
Try removing the UpdateCam on disconnect so it should be like RunService.Stepped:Disconnect() JesseSong 3916 — 3y
0
I'm not sure whether that will work JesseSong 3916 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

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()
0
thanks, I figured something out and it works! superbubba2020 6 — 3y
0
If my answer solved your problem, then accept it please! radiant_Light203 1166 — 3y
0
radiant_light did my comment work? I haven't scripted in a while JesseSong 3916 — 3y
0
also what parameters does :disconnect take? I checked everywhere, i couldn't find any source JesseSong 3916 — 3y
View all comments (3 more)
0
i'll accept your answer as soon as i get a response. JesseSong 3916 — 3y
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 radiant_Light203 1166 — 3y
0
ah ok, just double checking. anyways i accepted your answer! JesseSong 3916 — 3y
Ad

Answer this question