when the character first spawns in, it can create the viewmodel just fine. however, if the character dies, the variable stops working and this code block doesnt work.
character.ChildAdded:Connect(function(child)
print("h")
if child:IsA("Tool") and child.Name == "M4A1" then
viewmodel = game.ReplicatedStorage.Viewmodels.Viewmodel:Clone()
gunmodel = game.ReplicatedStorage.Items.M4A1:Clone()
viewmodel.Parent = camera
gunmodelAnims = gunmodel.Anims
mainmodule.weldGun(gunmodel)
mainmodule.equip(viewmodel, gunmodel, gunmodelAnims.Hold)
end
end)
variable
local character = localplayer.Character or localplayer.CharacterAdded:Wait()