Hello! I’m currently trying to make a viewportframe showing a model (character model) playing a random animation.
This is the serverscript:
while true do
print("start")
if math.random(1,4) == 1 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a1)
anim:Play()
print("1")
elseif math.random(1,4) == 2 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a2)
anim:Play()
print("2")
elseif math.random(1,4) == 3 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a3)
anim:Play()
print("3")
elseif math.random(1,4) == 4 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a4)
anim:Play()
print("4")
end
print("done")
wait(60)
for i,v in pairs(script.Parent.Humanoid.Animator:GetPlayingAnimationTracks()) do
v:Stop()
end
if math.random(1,4) == 1 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a1)
anim:Play()
print("1")
elseif math.random(1,4) == 2 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a2)
anim:Play()
print("2")
elseif math.random(1,4) == 3 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a3)
anim:Play()
print("3")
elseif math.random(1,4) == 4 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a4)
anim:Play()
print("4")
end
wait(60)
end
You should really research on how to write compact code, instead of your
if math.random(1,4) == 1 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a1)
anim:Play()
print("1")
elseif math.random(1,4) == 2 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a2)
anim:Play()
print("2")
elseif math.random(1,4) == 3 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a3)
anim:Play()
print("3")
elseif math.random(1,4) == 4 then
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent.a4)
anim:Play()
print("4")
end
you can just write
local anim = script.Parent.Humanoid.Animator:LoadAnimation(script.Parent["a"..tostring(math.random(1,4))])
anim:Play()
Do this and your problem of the statement being ignored will be solved too
(By the way, the reason for why your statement was ignored is because in your huge if-else statement a new number was being rolled for each check, so if you were unlucky you could have went through the entire if-else statement without activating any of its checks)
that still didn’t work
the character still has no animations playing
and i did do your method of compact code
while true do
print("start")
script.Parent.Humanoid.Animator:LoadAnimation(script.Parent["a"..tostring(math.random(1,4))]):Play()
print("done")
wait(20)
for i,v in pairs(script.Parent.Humanoid.Animator:GetPlayingAnimationTracks()) do
v:Stop()
end
script.Parent.Humanoid.Animator:LoadAnimation(script.Parent["a"..tostring(math.random(1,4))]):Play()
wait(20)
end