Hello everyone, currently I´m trying to make a tycoon and I want to play animations to a npc which can be bought for cash, but the npc is not doing an Animation, can I fix that?
local animationId = 15016188161
game.InsertService:LoadAsset(animationId).Parent = game.ReplicatedStorage
local controller = script.Parent.Humanoid
while true do
wait(1)
controller:LoadAnimation(script.Animation):Play()
end
I don´t know if this is important but here is my animation script:
local function AnimateBuild(Model)
for _, v in pairs(Model:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("UnionOperation") then
local OriginalCFrame = v.CFrame
local OriginalSize = v.Size
local OriginalTransparency = v.Transparency
local PositionOffset = Vector3.new(math.random(-2, 2), math.random(-2, 2), math.random(-2, 2))
local RotationOffset = CFrame.Angles(math.rad(math.random(-3, 3)), math.rad(math.random(-3, 3)), math.rad(math.random(-3, 3)))
v.CFrame = v.CFrame * CFrame.new(PositionOffset) * RotationOffset
v.Transparency = 1
backgroundMusic:Play()
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
local transparencyTweenInfo = TweenInfo.new(0.25, Enum.EasingStyle.Quart, Enum.EasingDirection.Out)
local tween = TweenService:Create(v, tweenInfo, {CFrame = OriginalCFrame})
local transparencyTween = TweenService:Create(v, transparencyTweenInfo, {Transparency = OriginalTransparency})
tween:Play()
transparencyTween:Play()
tween.Completed:Connect(function()
v.CFrame = OriginalCFrame
v.Transparency = OriginalTransparency
end)
end
end
end
ReplicatedStorage.Remotes:WaitForChild("BuildAnimation").OnClientEvent:Connect(function(Model)
print("called")
AnimateBuild(Model)
end)
this is my playAnimation script for purchases when I buy something using a button:
if playAnimation then
for _, v in toSpawn:GetDescendants() do
if v:IsA("BasePart") then
v.CanCollide = false
local particle = script.PurchaseParticle:Clone()
particle.Parent = v
task.spawn(function()
task.wait(0.01)
particle:Emit(80/#toSpawn:GetDescendants())
end)
task.delay(3, function()
particle:Destroy()
end)
end
end
task.wait(0.01)
remotes.BuildAnimation:FireClient(player, toSpawn)