I have problem with animating

Hi i tried to animate npc, but it returned after animation to its humanoid position so i thought i need to add mark and coresponding event. But all tutorials say put it in local script, but it is npc so it is on server and there is no client side (as far as i know), so animation played corectly, but the event was never called, silently without error

this is my code and it is placed into script its parent is npc root file
print(“ok”)
local ready=false;
while true do

    if game.Lighting.ClockTime < 8 then 
        --print(game.Lighting.ClockTime,game.Lighting.ClockTime <8)
        ready=true; 
    end
    if game.Lighting.ClockTime >=8 and ready==true then 
        ready = false;
        local an = workspace.Script.Mistr88.AnimSaves.ExportAnim --Instance.new("Animation");
        --an.AnimationId="6867865bca81889ad6c3d53cfe174b07";
        local a = workspace.Script.Mistr88.Humanoid:LoadAnimation(an)
        print("now")
        a.KeyframeReached:Connect(function(value)
        print(value)
        end)
        a:Play();

    end
    wait(1);
end

this will run at 8am the animation

sry for my english and also sry for some stupid mistaces maded by copiing it from my studio to forum and from it to this forum xD (on the first forum it was long time without answer and this forum is quicker)

thx for answer

3 Likes

and also sry for bad problem decripting its my first question

To be honest im not 100% sure what the question is but I think your asking how to check if time time is 8 on lighting and then to play an animation (may be wrong) but I made this script that does that

while wait(1) do
lighting = game:GetService(‘Lighting’)
if lighting.ClockTime == 8 then
anim = Instance.new(‘Animation’)
anim.AnimationId = ‘rbxassetid://31617132’
if script.Parent:FindFirstChild(‘Humanoid’) then script.Parent:FindFirstChild(‘Humanoid’):LoadAnimation(anim):Play() end
print(‘Its 8’)
end
end

this will check every second if the time is 8 and if it is will play an animation (would require additional checks to make sure it only played once but it shows the point
if this isn’t your question than please tell me.

2 Likes

sry but no
it all work but it dont call marker event

and also you code can (no must but can) not work if i will make fast day time cicle because it can go thru 8 hours without activating this and also with slow cycle can activate 2times my code say if time it<than 8 get ready and if it is >=8 and i am ready, run code and unready

If you’re using markers, you need to use GetMarkerReachedSignal. As for animations, you can’t load an export like that, pretty sure. The AnimationId you commented out is invalid: publish your animation first and get the id.

1 Like

so 1) i am sure i can load it because animation work
and 2) i tried keyframe and also marker event and no of them worked (GetMarkerReachedSignal and KeyframeReached)

1 Like

But only problem is to execute the marker event

1 Like
  1. You need to export the animation to ROBLOX and then make it private.
  2. Try this code; make sure to add the asset ID!
    if game.Lighting.ClockTime < 8 then 
        --print(game.Lighting.ClockTime,game.Lighting.ClockTime <8)
        ready=true; 
    end
    if game.Lighting.ClockTime >=8 and ready==true then 
        ready = false;
        local an = Instance.new("Animation");
        an.AnimationId=""; --Add the Roblox ASSET ID here
        local a = script.Parent.Mistr88.Humanoid:LoadAnimation(an)
        print("now")
        a:Play();
        a.KeyframeReached:Connect(function(value)
        print(value)
        end)
    end
    wait(1);
end
3 Likes

Ok so if i understand it i must not use id for play but i must use it for adding events?

1 Like

No; You cannot play via a Animation save at all.
You MUST Export it to Roblox.

1 Like

Realy my code work well except the event (but the animation is published so as far as I know I load it including its ID)

1 Like

I tried it and it played only the event was unsuccessful but there was no error or waring

1 Like

What do you want the event to do?

1 Like

so first run at all keyframes and when this will work run on the marker named end

1 Like

That doesn’t make any sense to me.
Please re-phrase that.

I am debugging this on keyframe event because I see if I have keyframes and than when it work change event to marker event

1 Like

And I want just to run the event

1 Like
a.KeyframeReached:Connect(function(value)
   print(value)
end)

It seems as though you’ve never defined what the Keyframe’s name is? Its supposed to be more like this (basically identify if it reaches that certain keyframe)

YourAnimation(Probably a).KeyframeReached("TheKeyframe'sName"):Connect(function(Value)
-- Bla bla
print(Value) -- If you want
end)

(Correct me If i’m wrong though)

2 Likes

And where I find keyframe’s name

1 Like