#Model Flicker

1 messages · Page 1 of 1 (latest)

pine lark
#

So I am making a gun framework and whenever the viewmodel is equipped it flickers the "t-pose" for a frame or two then plays the equip animation normally.
Viewmodel animations are set everytime the player equips the related tool
I have the viewmodel preloaded via local script

scarlet thunder
pine lark
#

ok fine i can send code 💔

#

@scarlet thunder

scarlet thunder
# pine lark

why agony ```lua
tool.Equipped:Connect(function()
createViewmodel()

    ...

-- Plays Equip Anim
tool.Equipped:Connect(function()
    equipTrack:Play(0)
end)

end)```

pine lark
#

fair point 😭

#

well

#

there is a reason

scarlet thunder
#

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

scarlet thunder
#

and you never disconnect them agony

pine lark
#

how 2 disconnect : D

#

is it literally like

#

example:Disconnect()?

scarlet thunder
#

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

pine lark
scarlet thunder
#

so its no wonder things are acting weird

regal mist
#

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

scarlet thunder
#

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

pine lark
#

but thats obviously

scarlet thunder
#

that's why you're getting a t-pose

pine lark
#

not smart

scarlet thunder
scarlet thunder
pine lark
#

so for the animations

scarlet thunder
#

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

pine lark
#

should i set them up a different way?

scarlet thunder
#

with how you have it, it's called every time it is equipped

pine lark
scarlet thunder
#

wat no

scarlet thunder
#

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

pine lark
#

so basically just disconnect shit

#

aight and for the animations

scarlet thunder
#

dont connect events inside other events unless you're very careful about what you're doing.

pine lark
#

should i have the IDs for the anims preset when its in rep storage

#

and not when equipped

scarlet thunder
#

it's the animationtracks that have a load limit

pine lark
#

ima get this shit straight

pine lark
#

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

scarlet thunder
pine lark
#

i read my script

#

the more i think

#

what the fuck

#

was i trhinking

#

i need to sleep

#

💀

#

ill send updated shit

scarlet thunder
pine lark
pine lark
#

i did not fix the flicker and it copies itself and stuff oh yay 🤠

scarlet thunder
scarlet thunder
#

try to avoid using one massive function

pine lark
#

yeah i keep thinking thats not the best thing

#

aight ill do that

#

shouldnt be too bad

scarlet thunder
#

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```
pine lark
#

slowly cleaning it up

distant heron
pine lark