I’ve created my own Client VFX system, where, upon hitting a certain input, a animation plays and sends a remote event to a server. The server deals with the hitbox and welding the characters together and whatnot, and I use ‘FireAllClients()’ to send the VFX to the client. In the client, I use a module script to handle the VFX. My problem, however, when I try to use ‘Animator.AnimationPlayed’, it doesn’t detect the specific animation (Kamehameha) until the 2nd or 3rd time using the move (playing the animation).
Local Script (handles animations and remote events):
KameAnimation.Event:Connect(function()
--Redefining variables since, after death, the variables turn to nil.
char = plr.Character or plr.CharacterAdded:Wait()
hum = char:WaitForChild("Humanoid")
animator = hum:WaitForChild("Animator")
-- I do attribute checks on the server, but I'm only checking here because I have a 'No Cooldown' feature, and if it's enabled, the animation would play multiple times.
if char:GetAttribute("Attacking",true) then return end
if char:GetAttribute("Animation",true) then return end
if char:GetAttribute("Ragdolled",true) then return end
if char:GetAttribute("Stunned",true) then return end
if char:GetAttribute("Blocking",true) then return end
if char:GetAttribute("Dashing",true) then return end
if char:GetAttribute("CantAttack",true) then return end
if hum.Health <= 0 then return end
local function LoadKHHAnim(char)
local KHHAnim = animations:WaitForChild("Attacks"):WaitForChild("Kamehameha"):WaitForChild("KameHameHa")
local currAnim
currAnim = KHHAnim
return currAnim
end
local kameAnim = LoadKHHAnim(char)
local playkameAnim = animator:LoadAnimation(kameAnim)
playkameAnim:Play()
--Hitbox/Weld/Sanity checks on server.
KameEvent:FireServer()
end)
--FireAllClients event
KameVFX.OnClientEvent:Connect(function(character : Model)
local KameModule = require(script:WaitForChild("Kamehameha"))
KameModule.MakeVFX(character)
end)
Module Script (handles VFX and Animation Keyframes):
local module = {}
local effects = script:WaitForChild("Effects")
function module.MakeVFX(character : Model)
local humRP : BasePart = character:WaitForChild("HumanoidRootPart")
local hum : Humanoid = character:WaitForChild("Humanoid")
local Animator : Animator = hum:WaitForChild("Animator")
local connection : RBXScriptConnection
connection = Animator.AnimationPlayed:Connect(function(kameAnim : AnimationTrack)
if kameAnim.Animation.AnimationId == "rbxassetid://16552578293" then --Checking if animation IS the Kamehameha animation. But for some reason, the code doesn't recognize it as the Kamehameha animation until the 2nd or 3rd time running the code.
kameAnim.KeyframeReached:Connect(function(kf : KeyframeMarker)
if kf == "Charge" then
local LeftArm : BasePart = character:WaitForChild("Left Arm")
local Kameball : BasePart = effects:WaitForChild("Kamehameha"):WaitForChild("KameBall"):Clone()
Kameball.Parent = character
Kameball.Massless = true
Kameball.CanCollide = false
Kameball.Anchored = false
local KameWeld = Instance.new("Weld",LeftArm)
KameWeld.Name = "Kameweld"
KameWeld.Part1 = LeftArm
KameWeld.Part0 = Kameball
KameWeld.Parent = character
KameWeld.C0 = CFrame.new(0.25,1,-0.05)
local PullEffect = effects:WaitForChild("Kamehameha"):WaitForChild("Pull"):Clone()
PullEffect.Parent = character
PullEffect.CFrame = Kameball.CFrame
end
if kf == "Shoot1" then
local LeftArm : BasePart = character:WaitForChild("Left Arm")
local kametrail : BasePart = effects:WaitForChild("Kamehameha"):WaitForChild("KameTrail"):Clone()
kametrail.Parent = character
local kameball : BasePart = character:FindFirstChild("KameBall")
local PullEffect : BasePart = character:FindFirstChild("Pull")
PullEffect:Destroy()
kametrail.CFrame = character:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(-0.15,0.05,-23)
kametrail.Orientation = character:WaitForChild("HumanoidRootPart").Orientation + Vector3.new(0,90,0)
end
if kf == "Shoot4" then
task.spawn(function()
character:WaitForChild("KameBall"):Destroy()
character:WaitForChild("KameTrail"):Destroy()
character:WaitForChild("Kameweld"):Destroy()
end)
end
end)
end
kameAnim.Stopped:Connect(function()
if connection then
connection:Disconnect()
connection = nil
end
local KB : BasePart = character:FindFirstChild("KameBall")
local KT : BasePart = character:FindFirstChild("KameTrail")
local L : BasePart = character:FindFirstChild("Lightning")
local P : BasePart = character:FindFirstChild("Pull")
if KB then KB:Destroy() end
if KT then KT:Destroy() end
if L then L:Destroy() end
if P then P:Destroy() end
end)
end)
end
return module
As I said, the ‘Animator.AnimationPlayed’ function does not detect the Kamehameha animation until the 2nd or 3rd time using it… I’ve looked everywhere but I physically cannot find a solution.