-
What do you want to achieve?
I want to run multiple animations at once using two functions (with humanoid and w/out humanoid). -
What is the issue?
The issue is that the animations sometimes all run, while sometimes only the humanoid function runs and the non-humanoid does. -
What solutions have you tried so far?
I tried putting the functions into a ModuleScript as well as returning the function (return).
Module:
local module = {}
module.RUN_ANIMATION = function(HUMANOID, ANIM)
local animator = HUMANOID:WaitForChild("Animator")
local animation = ANIM
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
end
module.RUN_OBJ_ANIMATION = function(RIG, ANIM)
local humanoid = RIG:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:Destroy()
end
local animController = Instance.new("AnimationController")
animController.Parent = RIG
local animator = Instance.new("Animator")
animator.Parent = animController
local animationTrack = animator:LoadAnimation(ANIM)
animationTrack:Play()
end
return module
Main Code To Run Animation:
for i, v in pairs(script.Parent:GetDescendants()) do
if v:IsA("ProximityPrompt") and v.Name == "Mix_Prompt" then
v.Triggered:Connect(function(player)
if v.BeingUsed.Value == false then
v.BeingUsed.Value = true
local CHANCES = {}
for i = 0, (100 - CONFIGURATION.MIX_SUCCESS_RATE), 1 do
table.insert(CHANCES, 1, false)
end
for i = 0, (CONFIGURATION.MIX_SUCCESS_RATE), 1 do
table.insert(CHANCES, 1, true)
end
local CHOSEN = CHANCES[math.random(1, #CHANCES)]
if CHOSEN == true then
Animation_Module.RUN_ANIMATION(player.Character.Humanoid, script.AnimationIDs.MixingBowlSuccess.Player)
Animation_Module.RUN_OBJ_ANIMATION(script.Parent.MixingBowl["Bowl 1"], script.AnimationIDs.MixingBowlSuccess.Bowl)
Animation_Module.RUN_OBJ_ANIMATION(script.Parent.MixingBowl["Ladle 1"], script.AnimationIDs.MixingBowlSuccess.Ladle)
else
Animation_Module.RUN_ANIMATION(player.Character.Humanoid, script.AnimationIDs.MixingBowlFail.Player)
Animation_Module.RUN_OBJ_ANIMATION(script.Parent.MixingBowl["Bowl 1"], script.AnimationIDs.MixingBowlFail.Bowl)
Animation_Module.RUN_OBJ_ANIMATION(script.Parent.MixingBowl["Ladle 1"], script.AnimationIDs.MixingBowlFail.Ladle)
end
v.BeingUsed.Value = false
end
end)
end
end
Please help! Thanks!