#Model Flicker
1 messages · Page 1 of 1 (latest)
why
```lua
tool.Equipped:Connect(function()
createViewmodel()
...
-- Plays Equip Anim
tool.Equipped:Connect(function()
equipTrack:Play(0)
end)
end)```
this is actually insane ```lua
tool.Equipped:Connect(function()
createViewmodel()
...
humanoid.Died:Connect(function()
if currentViewModel then
currentViewModel:Destroy()
-- currentViewModel = nil
end
end)
player.CharacterRemoving:Connect(function()
if currentViewModel then
currentViewModel:Destroy()
currentViewModel = nil
end
end)
end)```
you are creating multiple connections every time
every tool.equipped creates a new tool.equipped connection that playes the equiptrack
oh
and you never disconnect them 
oh dear ```lua
shootBullet.OnClientEvent:Connect(function()
local currentTime = time()
local withinCooldown = currentTime - lastSlashTime < coolDown
lastSlashTime = currentTime
if withinCooldown then
slash1 = not slash1
else
slash1 = false
end
if slash1 then
slash2Track:Stop()
slash1Track.TimePosition = 0
slash1Track:Play()
print("s1")
else
slash1Track:Stop()
slash2Track.TimePosition = 0
slash2Track:Play()
print("s2")
end
end)```
yeah so like
the way you've structured this is actual madness
every equipped event connects a whole bunch of other events and never disconnects them so like every time the client receives a shootbullet, potentially hundreds to thousands of weapons that dont exist anymore will be playing their animation

so its no wonder things are acting weird
how would someone have played that long to spawn that many weapons
or enough to cause a huge issue
its bad practice
but dont think it should cause any massive issues
the first problem is the fact that lua -- Plays Equip Anim tool.Equipped:Connect(function() equipTrack:Play(0) end)
is connected inside another tool.Equipped connection
i tried doing like make it transparent for a sec then undo it it flickers once then after any other time its equipped it would be fine
but thats obviously
that's why you're getting a t-pose
not smart
ill fix this
thank you
yeah any time after the first one will work
this is why it doesnt work the first time
so for the animations
tbh since that is already within a tool.equipped event, you don't need to connect it again. just straight up play the equip track
should i set them up a different way?
oh ok
absolutely, starting with the fact you should only ever call loadanimation once
with how you have it, it's called every time it is equipped
which would cause delays and whatnot right?
wat no
bc of this
there's a hard cap of 255 animations you can load into an animation controller at once, when you hit the cap, animations wont load anymore

so basically just disconnect shit
aight and for the animations
dont connect events inside other events unless you're very careful about what you're doing.
should i have the IDs for the anims preset when its in rep storage
and not when equipped
the animation object is fine that can be wherever
it's the animationtracks that have a load limit
thank you
ima get this shit straight

local function cleanupAnimations()
for _, track in pairs(animationTracks) do
track:Destroy()
end
end
im like pretty sure this will fix one of the issues you mentioned
i'm not certain, would have to properly stress test it which i haven't done
the more
i read my script
the more i think
what the fuck
was i trhinking
i need to sleep
💀
ill send updated shit
terry davis ahh
i did not fix the flicker and it copies itself and stuff oh yay 🤠
break it up into smaller functions and test it
try to avoid using one massive function
if you end up with a function that only calls a bunch of other functions and maybe a small amount of internal state, you're doin it rite 👍
function handleEquip()
initCharacter()
initAnimations()
initSounds()
character:startFly() or whatever()
end```
Made me giggle