Hello there! The title pretty much says it all but here’s a little more info, The orb is pretty much tweened 3 studs up and there’s an animation that the character does that goes with it. Though my problem is that the animation plays after the tween does even thought anim:Play() is set before the tween.
all help would be appreciated
here’s the script:
-- services, variables and functions
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
-- code
ReplicatedStorage.CleoRemotes.HoverEvent.OnServerEvent:Connect(function(player, position)
local character = player.Character
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8457812087"
local anim = character.Humanoid:LoadAnimation(animation)
anim:Play()
local orb = ReplicatedStorage.CleoPowers.Orb:Clone()
orb.Position = position - Vector3.new(0,0.5,0)
orb.Name = player.Name.."'s orb"
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Circular)
local goal = {}
goal.Position = position + Vector3.new(0,3,0)
local tween = TweenService:Create(orb, tweenInfo, goal)
orb.Parent = workspace
tween:Play()
end)
I assume it’s delayed because the animation hasn’t loaded yet before the script was ran. You should load the animation way before the script is run so it’d play instantly.
Unless you have loaded it already, I’m not sure why.
I can’t load the animation before the code is ran because the line local anim = character.Humanoid:LoadAnimation(animation) requires the character and if i put it outside the remote event it wont work
Yeah you gotta find a way around it. That’s primarily the cause of animation delay. One way you could fix it is by preloading the animation in the same script for all players whenever they spawn.
I don’t know if you need to preload on server or client. Try to preload it locally first and see if the animation would play instantly. If it works, then no need to change your script.
In case it doesn’t, make a function on your script which finds the Animator (Humanoid:LoadAnimation() is deprecated) of the player’s character and then load the animation. Connect that function to a Player.CharacterAdded event.
Preloading animations can be achieved by creating a local script in ReplicatedFirst and using ContentProvider. Take a look at this documentation for code examples.