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

AnimationEvents beeing called as much times as the animation were ever played. Help?

Asked by
Necro_las 412 Moderation Voter
4 years ago
Edited 4 years ago

As far as i know:

  • Im using Animation Event to cast a spell at a certain point of the animation,
  • but everytime i call :Play() on the loaded track, it looks like it creates another extra parallel track,
  • when i call :Stop() the track is actually still there in the background and stopped.
  • Calling :Play() again creates a new one and restarts ALL of them.
  • The event (for firing a spell) is called as much times as there are animations ever played in the "background" when the point of MarkedSignal of the one showing animation is reached.

In the end: - When i start an animation, the number of progectiles it casts is somehow multiplied by the times i've casten before, but im not 100% this what i describled is causing it.

How do I fix that? How do I destroy the animation instead of just calling :Stop()? Or is there any other mechanic to make the old onimations be ignored?

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
if not character then
    character = game.Players.LocalPlayer.CharacterAdded:Wait()
end
local humanoid = character:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local SkyBlastControl = false
    local StormCast = workspace.StormCast -- mudar
    local StormCastTrack = humanoid:LoadAnimation(StormCast)

mouse.Button1Down:Connect(function()
    SkyBlastControl = true
    local hit = mouse.Hit
    StormCastTrack:Play() 
    StormCastTrack:GetMarkerReachedSignal("SkyBlast"):Connect(function()
        if SkyBlastControl == true then
            print("SkyBlastCasten")
        end
    end)
end)

mouse.Button1Up:Connect(function()
    SkyBlastControl = false
    StormCastTrack:Stop()
    print("unclicked")
    for _, track in ipairs(humanoid:GetPlayingAnimationTracks()) do
        if track == StormCastTrack then
            track:Stop()
            break
        end
    end
end)

Here is the output:

Necro_las applied edits to script StormScript - SkyBlastCasten - unclicked - SkyBlastCasten (x2) - unclicked - SkyBlastCasten (x3) - unclicked - SkyBlastCasten (x4) - unclicked (x5) - SkyBlastCasten (x9) - unclicked

0
Can we see the code so we can understand what is happening better? AlmostADemon 50 — 4y
0
There it is Necro_las 412 — 4y
0
Just made some edits that i realized now Necro_las 412 — 4y

1 answer

Log in to vote
0
Answered by
Necro_las 412 Moderation Voter
4 years ago

Solved.

":GetMarkerReachedSignal("SkyBlast"):Connect" creates a new connection with anim so it was duplicating the events, not the animations.

0
yay glad you solved it royaltoe 5144 — 4y
Ad

Answer this question