Hey,
Im working on a game and we’re making animations for the characters. The thing is that whenever i try to replicate the animations into the actual game, the animations don’t load propperly and they do weird things such as minimizing the movement of the animation, here’s an example:
EXPECTED ANIMATION TO PLAY:
ANIMATION PLAYING IN GAME:
This is the script i use to replicate animations (Inside a LocalScript inside StarterPlayerScripts)
local function SetAnim(object, animName)
local humanoid = object:WaitForChild("Humanoid")
local animationsFolder = object:WaitForChild("Animations")
if humanoid and animationsFolder then
local animationObject = animationsFolder:WaitForChild(animName)
if animationObject then
local animator = humanoid:FindFirstChild("Animator")
local playingTracks = animator:GetPlayingAnimationTracks()
for i, track in pairs(playingTracks) do
if track.Name == animName then
return track
end
end
local animationTrack = animator:LoadAnimation(animationObject)
return animationTrack
end
end
end
local function PlayAnim(object, animName)
local animationTrack = SetAnim(object, animName)
if animationTrack then
animationTrack:Play()
else
warn("Animation Track Corrupted Or Does Not Exist")
end
end
workspace.Game.Towers.ChildAdded:Connect(function(object)
PlayAnim(object, "Idle")
end)
animateTowerEvent.OnClientEvent:Connect(function(tower, animName)
PlayAnim(tower, animName)
end)
I don’t know where in your code that is but it seems to me that the animation is played multiple times. I have had issues like this multiple times and I recognize it. For some reason when you run the animation, it runs multiple times. I suggest troubleshooting at that part of the script
function tower.Attack(newTower, player)
local config = newTower:FindFirstChild("Config")
local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
local targetPosition = target.HumanoidRootPart.Position
local targetCFrame = CFrame.lookAt(
newTower.HumanoidRootPart.Position,
Vector3.new(targetPosition.X, newTower.HumanoidRootPart.BodyGyro.CFrame.Y, targetPosition.Z))
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
animateTowerEvent:FireAllClients(newTower, "Attack", target) -- Fires Event
end
task.wait(0.1)
if newTower and newTower.Parent then
tower.Attack(newTower, player)
end
end
In the clip it seems like the tower is dealing 16 points of damage, check if thats what you intended. I honestly can’t figure this out it seems like it should be working.
I don’t however really understand the purpose of:
task.wait(0.1)
if newTower and newTower.Parent then
tower.Attack(newTower, player)
end
I’m guessing it works as a kind of loop to check if you can attack again? But why does it fire every 0.1 seconds? Wouldn’t that make the tower attack 10 times a second?
What that does is that loops it loops every 0.1 secs and checks if a enemy is near, if it is near, then it attacks and the loop stops till the attack is completed, but that has nothing to do with my animations not working