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

Troubles with :GetMarkerReachedSignal() inside of a function, why is it happening?

Asked by
Adr1z 0
2 years ago

Hi, I had some troubles with my scripts, I was trying to make a script where if an animation hits a certain keyframe it runs a function, but for some reason when I was testing it, the functions were run at the 1st frame of the animation but not the event frame. For example: This is the function I try to run when the animation hits the determined keyframe:

local function PauseResume(Track) 
        if Track.Speed == 1 then
            Track:AdjustSpeed(0)
        else
            Track:AdjustSpeed(1)
        end
    end

With this it runs properly:

  Track:GetMarkerReachedSignal("EventFrame"):Connect(function()
        PauseResume(Track)
    end)

But when trying to run it in a function, this fires at the 1st keyframe (not the keyframe I wanted it to run):

local function KeyframeEvent(Track,EventName,Funct)
        Track:GetMarkerReachedSignal(EventName):Connect(function()
        Funct()
        end)            
    end
KeyframeEvent(Track,"EventFrame",PauseResume(Track))

Why does this happen?

Answer this question