animations local script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local AnimateTowerEvent = events:WaitForChild("AnimateTower")
local function SetAnimation(object, animName)
local humanoid = object:WaitForChild("Humanoid")
local animationsFolder = object:WaitForChild("Animations")
if humanoid and animationsFolder then
local AnimationObject = animationsFolder:WaitForChild(animName)-- tutaj sprawdzic
task.wait()
if AnimationObject then
local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
local playingTrack = animator:GetPlayingAnimationTracks()
for i, track in pairs(playingTrack) do
if track.Name == animName then
return track
end
end
local AnimationTrack = animator:LoadAnimation(AnimationObject)
return AnimationTrack
end
end
end
local function PlayAnimation(object, animName)
local AnimationTrack = SetAnimation(object, animName)
if AnimationTrack then
if animName == "Attack" then
AnimationTrack:Play(1, 1, 0.5)
end
if animName == "Idle" then
AnimationTrack:Play(1, 1, 0.15)
end
if animName ~= "Idle" then
AnimationTrack:Play()
end
else
warn("Animation Track Doesnt Exist")
end
end
workspace.Mobs.ChildAdded:Connect(function(object)
PlayAnimation(object, "Walk")
end)
workspace.Towers.ChildAdded:Connect(function(object)
PlayAnimation(object, "Idle")
end)
AnimateTowerEvent.OnClientEvent:Connect(function(object, animName)
PlayAnimation(object, animName)
end)