-
What do you want to achieve? Keep it simple and clear!
I am working on a reload animation for a weapon. Currently, there are two mags (one is off-screen, one is visible and attached to the gun). When I reload, it takes the off-screen mag, removes the mag in the gun, places the new mag into the gun and discards the old mag. -
What is the issue? Include screenshots / videos if possible!
Because of how roblox plays animations, it instantly teleports the old mag to the new mag,which is very visible.
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried to, but haven’t found any that talk on this topic explicitly.
Could you please include a little bit of the script? Thanks.
Sure, sorry for the late response. It’s a bit of a mess:
local function SameAnimCheck(Name, DontStopAnim)
--This function runs an approximate check only. Direct not needed here as the table it's looking through is very small.
if Name == nil then
for _, v in ipairs(CurrentAnims) do
local match = string.match(v.Name, "(.*)"..AnimationName)
print(match)
if match and not(DontStopAnim) then
print(v.Name)
--print(match)
v:Stop()
elseif match and DontStopAnim then
print("Returning true to indicate animation is playing")
return true
end
end
else
for _, v in ipairs(CurrentAnims) do
local match = string.match(v.Name, "(.*)"..Name)
print(match)
if match then
print(v.Name)
--print(match)
v:Stop()
end
end
end
end
local function StopOtherAnims(TableToIgnore, StopRef)
for _, v in ipairs(CurrentAnims) do
local TableMatch = false
local match = string.match(v.Name, "(.*)"..AnimationName)
print(match)
if not match then
if TableToIgnore then
for _, x in ipairs(TableToIgnore) do
local Lookup = string.match(v.Name, x)
if Lookup then
print(Lookup)
print(x)
print(v.Name)
TableMatch = true
end
end
end
if TableToIgnore and TableMatch then
print("Name in table to ignore")
else
print(v.Name)
if string.match(v.Name, "Ref") and StopRef == nil then
print("Ref found, will not stop.")
else
v:Stop()
end
end
end
end
end
local AnimationTrack
if Animation ~= nil then
if Animation.Parent.Name == "SharedAnimations" and RefCheck() then
local RefAnimationTrack = Animator:LoadAnimation(AnimFinder("Ref"))
RefAnimationTrack.Looped = true
RefAnimationTrack:Play()
end
if AnimationName == "Walk" then
local IsWalkPlaying = SameAnimCheck(nil, true)
if not IsWalkPlaying then
StopOtherAnims()
AnimationTrack = Animator:LoadAnimation(Animation)
AnimationTrack.Looped = true
AnimationTrack:Play()
end
elseif AnimationName == "dblstk_TacReload" or AnimationName == "dblstk_SpdReload" then
SameAnimCheck()
StopOtherAnims(nil, true)
AnimationTrack = Animator:LoadAnimation(Animation)
AnimationTrack.Looped = false
AnimationTrack:Play()
Hopefully this helps?